Reputation: 1
Hi I am encountering the issue in Angular and aws-amplify v6
UserUnAuthenticatedException: User needs to be authenticated to call this API
I have configured the Amplify in my main.ts Amplify.configure(config)
varibale config
with this format.
{
"Auth": {
"Cognito": {
"userPoolClientId": "<<clientWebKeyId>>",
"userPoolId": "<<user_pool_id>>",
"identityPoolId": "<identity_pool_id>>",
"signUpVerificationMethod": "code",
"loginWith": {
"oauth": {
"domain": "xxxxx.auth.ap-southeast-1.amazoncognito.com",
"scopes": [
"phone",
"email",
"profile",
"openid",
"aws.cognito.signin.user.admin"
],
"redirectSignIn": [
"http://localhost:4200/login"
],
"redirectSignOut": [
"http://localhost:4200/"
],
"responseType": "code"
}
}
}
}
}
I also have an AuthGuard
that calls fetchAuthSession
to check if there is a logged in user; and redirect to Cognito hosted UI if the user is not authenticated
xxx.auth.ap-southeast-1.amazoncognito.com/login?response_type=code&.........redirect_uri=http://localhost:4200/login
Which works fine, but after login, putting up the correct credentials to the Cognito Hosted UI and redirected to the redirect_uri
value it gets stuck saying: UserUnAuthenticatedException
This works fine before v5 with diffrent format of configuration value. But having trouble in migrating to v6.
I have tried to migrate the V5 amplify to V6 in Angular Framework. Can you help me what did I do wrong?
I am using Angular 19, aws-amplfy version 6.12.3
Upvotes: 0
Views: 38
Reputation: 1
I already solved the problem, instead of using the manual redirect windows.location.replace(cognitoHostedURI)
use the await signInWithRedirect ()
and it will automatically redirect to cognito hosted UI with required parameters.
Upvotes: 0