Open Maayanyeru123 opened 4 months ago
+1 I am using amplify Authenticator UI and facing the same issues, the cookies are not set, the middleware is unable to retrieve the user
Hi @Maayanyeru123 @hasadata thanks for opening this issue.
Looking at @Maayanyeru123 's configuration, I anticipate you are calling signInWithRedirect
from the route /signin
, after your end user sign in at Google's UI, it redirects your end user back to the route /home
. If that's the case, you would need to follow this instruction to ensure the OAuth completion listener is added to your /home
route so it can completes the sign in flow and persist the auth token in cookie store.
adding the import fixed the issue
Thanks for the confirmation, @hasadata.
@Maayanyeru123, let us know if it resolves it for you as well.
Thanks for the confirmation, @hasadata.
@Maayanyeru123, let us know if it resolves it for you as well.
Not for me :) probably something I am missing here. The Home page is secured asset so implementing the import 'aws-amplify/auth/enable-oauth-listener'; will even work?
I fixed it with an ugly hack i created a middle page called redirect but this is so ugly
@Maayanyeru123, would you mind sharing the hacky way that you had to work around this? Wondering if we can provide any suggestions on it if you can share the frontend code. Thanks!
@Maayanyeru123, would you mind sharing the hacky way that you had to work around this? Wondering if we can provide any suggestions on it if you can share the frontend code. Thanks!
Hey,
So I have created the following page redirect that is not protected by the middleware it imports aws-amplify/auth/enable-oauth-listener
it is working perfectly fine but when i am putting it on the protected resource(Home Page) it doesn't work
"use client";
import 'aws-amplify/auth/enable-oauth-listener';
import { useRouter } from "next/navigation";
import { useAppSelector } from '@/app/redux/store';
import { useEffect } from 'react';
import { HOME} from '@/app/utils/client/consts';
import { getCurrentUser } from "aws-amplify/auth";
function Redirect() {
const router = useRouter();
const username = useAppSelector((state:any)=>state.AuthReducer.value.username);
let currentUser;
useEffect(() => {
async function goToHome() {
currentUser = await getCurrentUser();
router.push(HOME);
}
goToHome();
}, []);
return (
<div>
{currentUser}
</div>
);
};
export default Redirect;
The currentUser = await getCurrentUser();
returns the user correctly.
Can you share please more on how did call the Redirect. Im facing the same issue. It'll be helpful to me
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
Authentication, GraphQL API, Storage
Amplify Version
v6
Amplify Categories
auth
Backend
Amplify CLI
Environment information
Describe the bug
When using NextJs middleware as stated in Amplify documentation after signing in with Google provider "await fetchAuthSession" Doesn't return the signing user
Expected behavior
Getting the signing user session
Reproduction steps
1, going to app Home page
Code Snippet
aws-exports.js
serverUtils.ts
layout.tsx
middleware.ts
SocialLoginButton.tsx
Log output
aws-exports.js
/ eslint-disable / // WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.
const awsmobile = { "aws_project_region": "eu-west-1", "aws_cognito_identity_pool_id": "XXXX", "aws_cognito_region": "eu-west-1", "aws_user_pools_id": "XXXXX", "aws_user_pools_web_client_id": "XXXXX", "oauth": { "domain": "XXXXXX", "scope": [ "phone", "email", "openid", "profile", "aws.cognito.signin.user.admin" ], "redirectSignIn": "http://localhost:3000/home", "redirectSignOut": "http://localhost:3000/login/signin", "responseType": "code" }, "federationTarget": "COGNITO_USER_POOLS", "aws_cognito_username_attributes": [], "aws_cognito_social_providers": [ "GOOGLE" ], "aws_cognito_signup_attributes": [ "EMAIL" ], "aws_cognito_mfa_configuration": "OFF", "aws_cognito_mfa_types": [ "SMS" ], "aws_cognito_password_protection_settings": { "passwordPolicyMinLength": 8, "passwordPolicyCharacters": [] }, "aws_cognito_verification_mechanisms": [ "EMAIL" ] };
export default awsmobile;
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response