Skip to content

Chore/update remix auth GitHub #944

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

Merged
merged 7 commits into from
Feb 22, 2025

Conversation

rperon
Copy link
Contributor

@rperon rperon commented Feb 21, 2025

This PR update remix-auth and remix-auth-github to the latest version, to close #932 .

The main chalenge in this PR was to update the mock implementation done by remix-auth-github.

Test Plan

This needs to be deployed and tested with Github.

Checklist

  • Tests updated
  • Docs updated

Screenshots

Update authentication libraries to latest versions:
- remix-auth from 3.7.0 to 4.1.0
- remix-auth-github from 1.7.0 to 3.0.2

Refactor authentication implementation to match new library requirements, including:
- Removing connection session storage
- Updating GitHub strategy configuration
- Adjusting authentication callback handling
@rperon
Copy link
Contributor Author

rperon commented Feb 21, 2025

Sorry, there is one test failing, for some reason we don't receive the throw from the loader...

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

I'm very much looking forward to this change. Thank you so much for working on it. I just have a couple of questions and we'll want to make sure the tests all pass as well.

Comment on lines -7 to -18
export const connectionSessionStorage = createCookieSessionStorage({
cookie: {
name: 'en_connection',
sameSite: 'lax', // CSRF protection is advised if changing to 'none'
path: '/',
httpOnly: true,
maxAge: 60 * 10, // 10 minutes
secrets: process.env.SESSION_SECRET.split(','),
secure: process.env.NODE_ENV === 'production',
},
})

Copy link
Member

Choose a reason for hiding this comment

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

I'm confused why changing this was necessary because it looks like we've now lost the ability to display errors as the user goes between different pages in the OAuth flow. And I don't think that this change was necessary for upgrading to Remix auth. Can you help me understand why this change was made?

Choose a reason for hiding this comment

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

This is no needed anymore since Remix Auth doesn't receive a session storage instance anymore, instead the strategy uses @mjackson/headers to save the data it needs in a cookie during the auth process.

Then after the user is back in the app from GitHub it you need to save the data in your session storage yourself, AFAIK you already did this anyway so there's no change in that part.

Choose a reason for hiding this comment

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

Also related to error handling, now the strategies always throw an error, so you handle them with a try/catch

Copy link
Member

Choose a reason for hiding this comment

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

Great to know! Thanks!

@@ -35,7 +35,7 @@ test('when auth fails, send the user to login with a toast', async () => {
consoleError.mockImplementation(() => {})
server.use(
http.post('https://github.com/login/oauth/access_token', async () => {
return new Response('error', { status: 400 })
return new Response(null, { status: 400 })
Copy link
Contributor Author

@rperon rperon Feb 22, 2025

Choose a reason for hiding this comment

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

I had to change from "error" to null because the test was in timeout, stuck in the await response.body.cancel() call inside the arctic library. Cf. screenshots.
Screenshot 2025-02-22 at 16 03 52

@rperon
Copy link
Contributor Author

rperon commented Feb 22, 2025

Thanks for your feedback. Grad to help :)
I fixed the test, do you have another feedback for me ?

Of course this still has to be tested on a deployed server ;)

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Thank you so much! I’m going to merge and pray it works when deployed. If not I’ll fix it quick 😅

this is something I’ve wanted done in a while so I really appreciate your help!

@kentcdodds kentcdodds merged commit 54cbd0c into epicweb-dev:main Feb 22, 2025
5 checks passed
@kentcdodds
Copy link
Member

Well, it took a couple tries, but it's working in production now 😅

@rperon
Copy link
Contributor Author

rperon commented Feb 22, 2025

Well done 👍

@kentcdodds
Copy link
Member

Seriously, thank you! I had tried upgrading remix auth once or twice and I just never dug in deep enough to figure out what changes needed to happen so it's been in the back of my mind for a while. I'm so glad to have this now!

@rperon rperon deleted the chore/update-remix-auth-github branch February 24, 2025 08:55
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.

Update the remix-auth packages
3 participants