Immediately prompting for signin
currently I have this in home:
but this is not working, I would like the user to sign in as soon as they hit the page and keep them logged in, however when they sign in, it asks them to sign again... always in a loop
8 Replies
@sarahmiller321 Pass the method you want them to sign in with in the function
Also, the way you have it currently set up is a bit skewed. You'd probably want to check for auth in getServerSideProps, as with your useEffect, the very first pass won't have session data
what do you mean?
thats the point no? they won't be logged in
This is an example of how it would be used
whats the difference here?
with serverSideProps @Pod
It will only run once, and it will get the auth session if it exists
where does getServerSession come from
Next/auth?
It's straight nextjs
If you want to redirect to sign in on the client rather than with
getServerSideProps
, you can just pass { required: true }
to useSession
https://next-auth.js.org/getting-started/client#require-session
This will accomplish what you were trying to achieve with the useEffect
.Client API | NextAuth.js
The NextAuth.js client library makes it easy to interact with sessions from React applications.