-
Notifications
You must be signed in to change notification settings - Fork 70
Next-Auth: Replace our auth system with next-auth #2543
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
Conversation
Refactor the invocation of the GraphQL mutation `Login` with next-auth `signIn`. It also refactor how the login errors are set and when to redirect to curriculum.
Invoke `signIn` for Signing up instead of GraphQL `Login` mutation. It also refactor how the errors are set.
When next-auth handles setting the user password, it can set the session.
Refactor success.tsx to get the session from `getSession` method instead of extracting it from the request.
|
@flacial is attempting to deploy a commit to the c0d3-prod Team on Vercel. A member of the Team first needs to authorize it. |
| discordAvatarUrl, | ||
| discordUsername, | ||
| isConnectedToDiscord: !!user.discordRefreshToken // using this to avoid a second fetch to get Discord username | ||
| isConnectedToDiscord: !!user.discordId // using this to avoid a second fetch to get Discord username |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has been changed to discordId because with how next-auth work, we can't put sensitive data such as the user Discord refresh token in the session.
Codecov Report
@@ Coverage Diff @@
## master #2543 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 186 186
Lines 3401 3414 +13
Branches 915 929 +14
=========================================
+ Hits 3401 3414 +13
|
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Since we migrated to next-auth, it's a bit hard to cache the session. By sending a request to get the session, the Apollo client will cache and the AppNav in the /curriculum page will display the login-signup buttons in loading-state
| const router = useRouter() | ||
| const [logoutUser] = useLogoutMutation({ | ||
| update(cache) { | ||
| cache.modify({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expose the cache so we can modify without having to execute a query. There's probably a reason for setting the lessonStatus to an empty array.
This reverts commit d5187ea.
Closes #1935
Changed files in detail
success.tsx: We were using a set of middlewares to populate the user from. We now use the next-authgetSessionmethod to retrieve the session, and handle when a user is already connected to the same Discord account.login.tsxandsignup.tsx: We used the Apollo mutationssignupandloginto start the flow. This has been changed with the next-authsignInmethod.logoutContainer: We used the Apollo mutationlogoutto log out the user. We now usesignOutmethod by next-auth.nextAuth(session callback): Updated thesessioncallback to set thesession.useras the user from the database. This callback runs every time we callgetSessionoruseSession. The reason is that the data in the session stays outdated if one of them got updated from the client, such as if the user connected to discord. Created a custom credential provider that'll be used to handle the flow after the user confirm their email on signup flow.Fixes the bugs in the initial PR #1985:
Testing
Engineering changes 🔧
getSessionanduseSessionto get the user's session.Following
Handle the error thrown when a user is already connected to the same Discord account.