Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(webapp): restore magic link login on the login page#4220
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dad37ef
Revert "fix(webapp): show magic link confirmation instead of reloadin…
samejr 8e20947
fix(webapp): stop stale login errors reappearing on the login page
samejr f35965c
fix(webapp): drop text-wrap:balance from magic link confirmation copy
samejr fbdedf7
fix(webapp): clearer login error when WHITELISTED_EMAILS rejects an a…
samejr 32c2bdf
fix(webapp): also clear stale auth errors stored by the previous sess…
samejr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| area: webapp | ||
| type: improvement | ||
| --- | ||
| Clearer login error when an email address is blocked by the WHITELISTED_EMAILS setting: the message now explains the address isn't allowed on this instance instead of the ambiguous "This email is unauthorized". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| area: webapp | ||
| type: fix | ||
| --- | ||
| Fixed stale login errors: an error from a previous login attempt (for example a rejected email address) no longer keeps reappearing on the login page and no longer makes later, successful attempts look like they failed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -23,7 +23,10 @@ import { isGithubAuthSupported, isGoogleAuthSupported } from "~/services/auth.se | ||
| import { getLastAuthMethod } from "~/services/lastAuthMethod.server"; | ||
| import { commitSession, setRedirectTo } from "~/services/redirectTo.server"; | ||
| import { getUserId } from "~/services/session.server"; | ||
| import { getUserSession } from "~/services/sessionStorage.server"; | ||
| import { | ||
| commitSession as commitUserSession, | ||
| getUserSession, | ||
| } from "~/services/sessionStorage.server"; | ||
| import { ssoController } from "~/services/sso.server"; | ||
| import { flags as getGlobalFlags } from "~/v3/featureFlags.server"; | ||
| import { requestUrl } from "~/utils/requestUrl.server"; | ||
| @@ -111,8 +114,36 @@ export async function loader({ request }: LoaderFunctionArgs) { | ||
| showSsoAuth = (globalFlags as Record<string, unknown>).hasSso === true; | ||
| } | ||
| // Read the flashed auth error and, when one exists, commit the session so | ||
| // the flash is consumed. Reading without committing leaves the flash in the | ||
| // cookie, so a stale error (e.g. a once-rejected email address) would | ||
| // resurface on every future /login visit and make later, successful login | ||
| // attempts look like they failed. | ||
| const userSession = await getUserSession(request); | ||
| const error = userSession.get("auth:error"); | ||
| // get() only auto-clears flash-stored values. Sessions written before this | ||
| // fix stored the error with set(), which survives get() + commit — unset it | ||
| // explicitly so those sessions heal too instead of showing the stale error | ||
| // until the cookie's one-year maxAge runs out. | ||
| userSession.unset("auth:error"); | ||
| let authError: string | undefined; | ||
| if (error) { | ||
| if ("message" in error) { | ||
| authError = error.message; | ||
| } else { | ||
| authError = JSON.stringify(error, null, 2); | ||
| } | ||
| } | ||
| const headers = new Headers(); | ||
| if (error) { | ||
| headers.append("Set-Cookie", await commitUserSession(userSession)); | ||
| } | ||
| if (redirectTo) { | ||
| const session = await setRedirectTo(request, redirectTo); | ||
| headers.append("Set-Cookie", await commitSession(session)); | ||
| return typedjson( | ||
| { | ||
| @@ -121,39 +152,26 @@ export async function loader({ request }: LoaderFunctionArgs) { | ||
| showGoogleAuth: isGoogleAuthSupported, | ||
| showSsoAuth, | ||
| lastAuthMethod, | ||
| authError: null, | ||
| authError, | ||
matt-aitken marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| notice, | ||
| isVercelMarketplace: redirectTo.startsWith("/vercel/callback"), | ||
| }, | ||
| { | ||
| headers: { | ||
| "Set-Cookie": await commitSession(session), | ||
| }, | ||
| } | ||
| { headers } | ||
| ); | ||
| } else { | ||
| const session = await getUserSession(request); | ||
| const error = session.get("auth:error"); | ||
| let authError: string | undefined; | ||
| if (error) { | ||
| if ("message" in error) { | ||
| authError = error.message; | ||
| } else { | ||
| authError = JSON.stringify(error, null, 2); | ||
| } | ||
| } | ||
| return typedjson({ | ||
| redirectTo: null, | ||
| showGithubAuth: isGithubAuthSupported, | ||
| showGoogleAuth: isGoogleAuthSupported, | ||
| showSsoAuth, | ||
| lastAuthMethod, | ||
| authError, | ||
| notice, | ||
| isVercelMarketplace: false, | ||
| }); | ||
| return typedjson( | ||
| { | ||
| redirectTo: null, | ||
| showGithubAuth: isGithubAuthSupported, | ||
| showGoogleAuth: isGoogleAuthSupported, | ||
| showSsoAuth, | ||
| lastAuthMethod, | ||
| authError, | ||
| notice, | ||
| isVercelMarketplace: false, | ||
| }, | ||
| { headers } | ||
| ); | ||
| } | ||
| } | ||
15 changes: 15 additions & 0 deletions
15 apps/webapp/app/routes/login.magic/magicLinkEmailCookie.server.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { createCookie } from "@remix-run/node"; | ||
| import { env } from "~/env.server"; | ||
| // Carries the submitted email to the confirmation screen in a short-lived, | ||
| // httpOnly cookie rather than the URL, so the address never lands in access | ||
| // logs, browser history, or error-tracker breadcrumbs. Lives in a .server | ||
| // module: it calls createCookie at import time using server-only env, which | ||
| // throws if it ever evaluates in the client bundle. | ||
| export const magicLinkEmailCookie = createCookie("magiclink-email", { | ||
| maxAge: 60 * 10, | ||
| httpOnly: true, | ||
| sameSite: "lax", | ||
| secure: env.NODE_ENV === "production", | ||
| path: "/", | ||
| }); |
devin-ai-integration[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.