Category Archives: Web Development

Breaking the Internet

Cognito Hosted UI User Pool – Google not showing

Hi everyone,

I’m implementing Cognito User Pools for an app and currently adding social providers (Google, Facebook, etc).

The setup process seems pretty straight forward, however the social options did not appear on my hosted ui.

It turned out that I’d missed the last step in the documentation:
– Go to “App Client Settings” (left hand menu under App integration)
– Look for “Enabled Identity Providers” and check any that you want to show

I found this a little unintuitive as I’d expected it to show once it was enabled in the “Identity Providers” section. I probably just need to learn to read ALL of the docs!

hosted-ui.JPG

The full documentation is available here: https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-social-idp.html

And the bulk of the configuration is performed here:
google-congito

Advertisements

Unable to create object of type ‘ApplicationDbContext’ – Updating to .NET Core 3.0

Hi everyone,

I’ve just updated to .net core 3.0 and have been hitting a few issues. I hit this one while trying to add a migration:

Unable to create an object of type ‘ApplicationDbContext’. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

Adding -verbose to this allowed me to narrow the cause down a little further:

PM> add-migration add-propertyid-to-entities-for-events -verbose
Using project ‘PropertyApi’.
Using startup project ‘PropertyApi’.
Build started…
Build succeeded.
C:\Program Files\dotnet\dotnet.exe exec –depsfile C:\Users\Celeste\Documents\repos\property-api\PropertyApi\bin\Debug\netcoreapp3.0\PropertyApi.deps.json –additionalprobingpath C:\Users\Celeste\.nuget\packages –additionalprobingpath “C:\Program Files\dotnet\sdk\NuGetFallbackFolder” –runtimeconfig C:\Users\Celeste\Documents\repos\property-api\PropertyApi\bin\Debug\netcoreapp3.0\PropertyApi.runtimeconfig.json C:\Users\Celeste\.nuget\packages\microsoft.entityframeworkcore.tools\3.0.0\tools\netcoreapp2.0\any\ef.dll migrations add add-propertyid-to-entities-for-events –json –verbose –no-color –prefix-output –assembly C:\Users\Celeste\Documents\repos\property-api\PropertyApi\bin\Debug\netcoreapp3.0\PropertyApi.dll –startup-assembly C:\Users\Celeste\Documents\repos\property-api\PropertyApi\bin\Debug\netcoreapp3.0\PropertyApi.dll –project-dir C:\Users\Celeste\Documents\repos\property-api\PropertyApi\ –language C# –working-dir C:\Users\Celeste\Documents\repos\property-api –root-namespace PropertyApi
Using assembly ‘PropertyApi’.
Using startup assembly ‘PropertyApi’.
Using application base ‘C:\Users\Celeste\Documents\repos\property-api\PropertyApi\bin\Debug\netcoreapp3.0’.
Using working directory ‘C:\Users\Celeste\Documents\repos\property-api\PropertyApi’.
Using root namespace ‘PropertyApi’.
Using project directory ‘C:\Users\Celeste\Documents\repos\property-api\PropertyApi\’.
Finding DbContext classes…
Finding IDesignTimeDbContextFactory implementations…
Finding application service provider…
Finding Microsoft.Extensions.Hosting service provider…
Using environment ‘Development’.
System.ArgumentNullException: Value cannot be null. (Parameter ‘implementationInstance’)

The key part here are the fact that it can’t find the config values and that it’s attempting to use the ‘Development’ env whereas it should be looking for ‘Local’.

It seems that during the upgrade all of my environment variables have been wiped. All that was required was to run the following (change local to match your environment):

$Env:ASPNETCORE_ENVIRONMENT = “Local”

Running the add-migration command should now user the local configuration. Thanks to the following link for the solution:
https://stackoverflow.com/a/50507486/522859

‘add-migration’ is not recognized as the name of a cmdlet – .net core 3.0

Hey everyone,

I recently upgraded my .net core 2.2 project to .net core 3.0. When trying to add a migration I hit the following error:

add-migration : The term ‘add-migration’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and
try again.
At line:1 char:1
+ add-migration events
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (add-migration:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

It turns out that there have been a few changes to how this all works. You’ll need to go to package manager console and run the following:

1) Install-Package Microsoft.EntityFrameworkCore.Tools
2) Update-Package Microsoft.EntityFrameworkCore.Tools
3) Get-Help about_EntityFrameworkCore

After running step three you should get something that looks like the following:

PM> Get-Help about_EntityFrameworkCore
ef-core

Covered in full here: https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell

View Raw SQL in EF Core – Simple Option

Hi everyone,

I’ve been looking for a simple way of viewing the raw output of sql in my local environment without having to make code changes and came across the following config setup:

{
“Logging”: {
“LogLevel”: {
“Default”: “Debug”,
“System”: “Information”,
“Microsoft”: “Information”
}
}

This will show the sql statements in your output window without requiring any additional code:
sql-output

Thanks to this stackoverflow post for the answer: https://stackoverflow.com/a/54704006/522859

Geography: one of the identified items was in an invalid format – Entity Framework

Hey everyone,

I’m currently working on a prototype using .net core, sql server, ef and NetTopologySuite to handle locations. While trying to save a location I ran into the following error:

Geography: one of the identified items was in an invalid format

My code was as follows:

using GeoAPI.Geometries;
using NetTopologySuite;
using NetTopologySuite.Geometries;

...
var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);
...
Location = geometryFactory.CreatePoint(new Coordinate(request.Lat, request.Lng))
...

The solution ended up being pretty straight-forward. Simply swap the latitude and longitude values when creating a coordinate:

Location = geometryFactory.CreatePoint(new Coordinate(request.Lat, request.Lng))

// Use this instead
Location = geometryFactory.CreatePoint(new Coordinate(request.Lng, request.Lat))

This is mentioned pretty clearly when reading the documents but I somehow skipped over it. Hopefully this will be able to help out anyone else who does the same thing!

Official docs: https://docs.microsoft.com/sv-se/ef/core/modeling/spatial

Simple React-Leaflet Location Picker Setup

Hi everyone,

Just thought I’d share a very simple react-leaflet setup in case it’s able to help anyone.

screencast-localhost_3889-2019.08.24-14_01_41.gif

Add the css and javascript for leaflet to public > index.html:

  
https://unpkg.com/leaflet@1.5.1/dist/leaflet.js">https://unpkg.com/leaflet@1.5.1/dist/leaflet.js

Install react-leaflet via npm or yarn, also add the dependencies:

npm install react-leaflet # npm
npm install leaflet react react-dom # npm

yarn add react-leaflet # Yarn
yarn add leaflet react react-dom # Yarn

Create the map component:

import React, { useState } from 'react'
import { Map, TileLayer, Marker, Popup } from 'react-leaflet'


const MapSimple = () => {

    const [location, setLocation] = useState({
        lat: 51.505,
        lng: -0.09,
        zoom: 13,
    });
    const position = [location.lat, location.lng];
    
    const setMarkerPosition = e => {
        setLocation({ ...e.latlng, zoom: 19 });
        console.log(`My location is: ${JSON.stringify(e.latlng, null, 3)}`)
    };

    return (
        
            <TileLayer
                attribution='© OpenStreetMap contributors'
                url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
            />
            
                
                   A sample popup.
                
            
        
    )
}

export default MapSimple;