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

Support RR7 & remix-auth@4 #54

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pskd73
Copy link

@pskd73 pskd73 commented Jan 22, 2025

Hello @pbteja1998 !

This package is great and wanted it to port to remix-auth@4 along with React Router 7 (latest Remix). Following are the significant changes to remix-auth@4

  1. remix is react-router. So Removed all remix dependencies
  2. sessionStorage and options is not passed in authenticate function now
  3. I am taking the sessionStorage in the constructor options
  4. Removed taking session keys as I am defining the types specifically
  5. Upgrading the tsconfig.json as per react-router specification
  6. Adding package-lock.json

@E-Kuerschner
Copy link

Great work on this! I am also blocked on migrating until these changes are in so I appreciate the initiative

@E-Kuerschner
Copy link

@pbteja1998 can we get a review on this? 🙏

Copy link

@E-Kuerschner E-Kuerschner left a comment

Choose a reason for hiding this comment

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

Awesome work! Thanks for getting the ball rolling on this

// remove the magic link and email from the session
session.unset(this.sessionMagicLinkKey)
session.unset(this.sessionEmailKey)
session.unset('magicLink')

Choose a reason for hiding this comment

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

couple of observations here:

  1. it looks like the ability to set one's own keys for the cookie storage is no longer available? This feels like a regression in my opinion
  2. to minimize breaking changes we should leave the default values as is e.g. auth:magiclink

session.flash(this.sessionErrorKey, { message })
const cookie = await sessionStorage.commitSession(session)
throw redirect(options.failureRedirect, {
session.flash('error', message)

Choose a reason for hiding this comment

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

any reason you're choosing to flash the message text directly as opposed to within an object?

@@ -197,24 +235,15 @@ export class EmailLinkStrategy<User> extends Strategy<

// This should only be called in an action if it's used to start the login process
if (request.method === 'POST') {
if (!options.successRedirect) {

Choose a reason for hiding this comment

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

would it not be useful to keep successRedirect as optional? It can be useful to defer the redirect to the app's business logic. In my apps I have the following for my verify loader:

const { email, name, isAdmin } = await auth.authenticate(
    "email-link",
    request,
    {
      failureRedirect: "/auth/login",
    },
  );

  const session = await getSession(request.headers.get("Cookie"));
  const redirectBackTo = session.get("auth:loginDestination");

  // set the session for a logged in/verified guest user
  session.set("user", { email, name, isAdmin });
  session.set("isGuest", true);
  session.set("emailSubscription", true);
  session.unset("auth:email");
  session.unset("auth:link");
  session.unset("auth:loginDestination");

  return redirect(redirectBackTo ?? "/", {
    headers: {
      "Set-Cookie": await commitSession(session),
    },
  });

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.

2 participants