Skip to content
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

FEAT: single session/login #119

Merged
merged 5 commits into from
Feb 26, 2024
Merged

FEAT: single session/login #119

merged 5 commits into from
Feb 26, 2024

Conversation

siinghd
Copy link
Collaborator

@siinghd siinghd commented Feb 26, 2024

This pr should add support #101

Key changes need to be added:

ENV: set JWT_SECRET, correctly as its being used

DB: user model has new field called token
NEXT_PUBLIC_BASE_URL_LOCAL="http://localhost:3000" -> set this to the correct one

Middleware: check for the token mismatch to redirect the user to signout.

Currently with nextauth you cannot logout the user on server side so im just redirecting the user to a page and doing singout in the useeffect.

Also middleware runtime is edge so it doesnt support db querying directly from there unless you don't use prisma accelerate and prisma edge client.

Missing: admin can logout the user

Copy link

netlify bot commented Feb 26, 2024

👷 Deploy request for charming-semolina-f274cf pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 43cb7ec

Copy link

vercel bot commented Feb 26, 2024

@siinghd is attempting to deploy a commit to the My Team Team on Vercel.

A member of the Team first needs to authorize it.

@siinghd
Copy link
Collaborator Author

siinghd commented Feb 26, 2024

wait before merging , let me add also the admin part and test it properly

@siinghd
Copy link
Collaborator Author

siinghd commented Feb 26, 2024

ok, should be working fine,

tested at https://incomparable-biscotti-b0e8a5.netlify.app

@hkirat NEXT_PUBLIC_BASE_URL_LOCAL(should be https://app.100xdevs.com , i think), JWT_SECRET needs to be set, NEXTAUTH_URL needs to be set too correct url (https://app.100xdevs.com) i think.

2024-02-26.12-10-11.1.mp4

admin:
Screenshot 2024-02-26 at 12 29 14 PM

@devsargam
Copy link
Collaborator

@siinghd displaying a toast to the end user would be a nice UX. Could you please accept those changes

return NextResponse.redirect(new URL('/invalidsession', req.url));
}
const user = await fetch(
`${process.env.NEXT_PUBLIC_BASE_URL_LOCAL}/api/user?token=${token.jwtToken}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing something or do middlewares run on the client?
Any reason for this to be a fetch and not a db call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to use prisma in middleware we need to use accelerate and prisma edge, prisma/prisma#21310, middleware runs on edge runtime

@hkirat
Copy link
Contributor

hkirat commented Feb 26, 2024

/bounty $150
Thankyou sir. One more comment but merging it in for now

@hkirat hkirat merged commit ea852bf into code100x:main Feb 26, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants