-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using Auth method to check if the user is logged in with SSR and then trying to signOut does not work #7223
Comments
Thanks for opening this issue @MontoyaAndres from #5435 (comment) 🙏 Can you share more on how you're doing sign in? Are you using |
@dbhagen You're having this same issue with https://github.com/dbhagen/next.js-authentication-aws, correct? If I were to drop-in |
@dbhagen I want to better understand this comment:
Do you mean the auth from the tutorial (https://dev.to/dabit3/the-complete-guide-to-next-js-authentication-2aco), or something else? |
I'm using the method
|
Maybe I can send you the cloudformation code generated by the amplify-cli? To understand what I'm doing? |
/* eslint-disable */
// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.
const awsmobile = {
"aws_project_region": "us-east-1",
"aws_cognito_identity_pool_id": "us-east-1:",
"aws_cognito_region": "us-east-1",
"aws_user_pools_id": "us-east-1_",
"aws_user_pools_web_client_id": "",
"oauth": {
"domain": "-dev.auth.us-east-1.amazoncognito.com",
"scope": [
"phone",
"email",
"openid",
"profile",
"aws.cognito.signin.user.admin"
],
"redirectSignIn": "http://localhost:3000/signinreturn/",
"redirectSignOut": "http://localhost:3000/signoutreturn/",
"responseType": "code"
},
"federationTarget": "COGNITO_USER_POOLS"
};
export default awsmobile;
Yes, that tutorial worked perfectly with |
Ahhh! The SSO redirect part to The way SSR Auth works at the moment is the If you were to redirect back to Alternatively, you can convert
I know it's not the flow you were expecting (client negotiation vs. server), but let me know if that works. Or let me know if I'm misunderstood entirely. I haven't had a chance to run the repository yet, but I do have a SSO version working: the difference is that it redirects back to the client to finish the login flow. |
I just hit the same issue. Before my modification on UniversalStorgage class, cookies no expiry date or maxAge configured. Then made my modification, protected setUniversalItem(key: keyof Store, value: string) {
this.cookies.set(key, value, {
path: "/",
// `httpOnly` cannot be set via JavaScript: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#JavaScript_access_using_Document.cookie
sameSite: true,
// Allow unsecure requests to http://localhost:3000/ when in development.
secure: window.location.hostname === "localhost" ? false : true,
maxAge: 24 * 60 * 60, // 24 hours in second,
});
} it works as I expected. |
It's weird... I mean, when the SSR support was released completely, I changed the Authentication of the application to use with SSR, as I showed... I don't know if this conversion affected In something? |
@endigo To be clear, sign in works for you but sign out isn't clearing cookies as expected? Can you share which browser you're in? |
@ericclemmons Sign in with username and password works fine. But sometimes federated login failed. I checked on Brave, Chrome, and Safari. |
@ericclemmons According this comment, in order to delete a cookie from
|
Hey @ericclemmons, hope you had a good holiday break! So now I'm looking into that UI to see what I need to implement so that I can implement my own UI, but have the handler functionality. |
Sorry, quick follow up to say I've committed my tests here: https://github.com/dbhagen/next.js-authentication-aws https://github.com/dbhagen/next.js-authentication-aws/blob/3ec7225c614b580c85b30cdf8be0a0024b1bb020/pages/profile.js#L37 vs. https://github.com/dbhagen/next.js-authentication-aws/blob/28f511cc61ba01d57c9f726c1db4885683ab686f/pages/test.js#L37 |
Ah, so running your example that Notice how the in progress check is amplify-js/packages/auth/src/Auth.ts Lines 1172 to 1204 in 4b58419
Once we resolve #6330, this should "just work". |
Oh, another note: it "just worked" with a username/password. The Google sign-in is where I saw the failure, leading me to believe this is an issue with #6330 . |
Any solution for this issue? |
Closing, as #7718 (via To install the latest version of npm install aws-amplify @aws-amplify/ui-react
# or
yarn add aws-amplify @aws-amplify/ui-react Be sure to install Let us know if you experience any issues! 🙏 |
Thanks @ericclemmons ! |
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs. Looking for a help forum? We recommend joining the Amplify Community Discord server |
Describe the bug
I'm using the Auth method to know if a user is logged in and then execute the signOut method to logout but does not work. Also, the
Auth.currentAuthenticatedUser()
throws an error that the user is not authenticated even when it is on SSR. I have just implemented this on Dev, I haven't tried on Prod.To Reproduce
First, I have added the
Amplify.configure({ ...config, ssr: true });
in the_app.js
file. Then, I created a function to detect if the a user is logged in when thegetServerSideProps
is executed. This iswithAuth
:I call this function on every private page the project has, like this:
It works fine, but when the user wants to signOut, like this:
Amplify still detects I'm logged in... Even when the user already executed the signOut function... And here's when the project starts to act weird, the method
withAuth
throws the user to/signin
even when is "logged in" but I can still navigate to any private page with the<Link />
component. I already tried removing the cache from the browser and tried with an incognito page, but nothing...One thing to mention is that I have a header component, to show the user photo and other info, I get this info using Auth in client-side using an
useEffect
. I don't know if using Auth in the header component and also in SSR affects something...Expected behavior
Work fine, when the user wants to signout
The text was updated successfully, but these errors were encountered: