I'm using Amplify Gen 2 and have a simple Angular 17 standalone app. When locally I run npx ampx sandbox
then ng serve
my app, I am able to signup and signin/signout multiple times. However, as soon as I alter the app and it reloads, I am signed out and on trying to sign in am warned There is already a signed in user.
I can access the user pool in AWS for my sandbox and sign the user out:
.. however, this makes no difference. The only way I can get it working again is to delete the sandbox and regenerate it.
There's nothing much going on in app.component:
<amplify-authenticator>
<ng-template
amplifySlot="authenticated"
let-user="user"
let-signOut="signOut"
>
<h1>Hello {{user?.signInDetails?.loginId}}</h1>
<button (click)="signOut()">Sign Out</button>
<h2>Welcome, {{ user.username }}!</h2>
</ng-template>
</amplify-authenticator>
Unsure if this is relevant, but in resource.ts the Amplify auth is configued as follows:
export const data = defineData({
schema,
authorizationModes: {
defaultAuthorizationMode: 'userPool',
},
});
Any ideas at all? Not getting much confidence in Amplify Gen 2 with such a basic blocker so early on...
I ran into this same issue and this is what fixed it for me.
In your app.component.ts
you should have a constructor with something like
constructor(public authenticator: AuthenticatorService) {
Amplify.configure(YOUR_IMPORTED_CONFIG_FILE);
}
You also need to add that at that right before defining your component
import YOUR_IMPORTED_CONFIG_FILE from '../your_config_path';
Amplify.configure(YOUR_IMPORTED_CONFIG_FILE);
@Component({
...
})