From 286f55fde1404531937d3cc263a6b5db01235776 Mon Sep 17 00:00:00 2001 From: Jim Nielsen Date: Wed, 6 Sep 2023 16:52:17 -0600 Subject: [PATCH 1/3] add signup button --- src/auth.ts | 5 +++-- src/constants/routes.ts | 1 + src/router.tsx | 12 ++++++++---- src/ui/components/PermissionOverlay.tsx | 26 +++++++++++++++---------- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/auth.ts b/src/auth.ts index 2afc29ffe0..186bb70dd5 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -40,7 +40,7 @@ async function getClient() { interface AuthClient { isAuthenticated(): Promise; user(): Promise; - login(redirectTo: string): Promise; + login(redirectTo: string, isSignupFlow?: boolean): Promise; handleSigninRedirect(): Promise; logout(): Promise; getToken(): Promise; @@ -57,10 +57,11 @@ export const authClient: AuthClient = { const user = await client.getUser(); return user; }, - async login(redirectTo: string) { + async login(redirectTo: string, isSignupFlow: boolean = false) { const client = await getClient(); await client.loginWithRedirect({ authorizationParams: { + screen_hint: isSignupFlow ? 'signup' : 'login', redirect_uri: window.location.origin + ROUTES.LOGIN_RESULT + diff --git a/src/constants/routes.ts b/src/constants/routes.ts index ccd48338e8..aeb5f9e7ff 100644 --- a/src/constants/routes.ts +++ b/src/constants/routes.ts @@ -3,6 +3,7 @@ export const ROUTES = { LOGOUT: '/logout', LOGIN: '/login', LOGIN_WITH_REDIRECT: () => '/login?from=' + encodeURIComponent(window.location.pathname), + SIGNUP_WITH_REDIRECT: () => '/login?signup&from=' + encodeURIComponent(window.location.pathname), LOGIN_RESULT: '/login-result', FILES: '/files', MY_FILES: '/files/mine', diff --git a/src/router.tsx b/src/router.tsx index 422fe7ac76..8555dab568 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -127,11 +127,15 @@ export const router = createBrowserRouter( // If they’re not authenticated, send them to Auth0 // Watch for a `from` query param, as unprotected routes will redirect // to here for them to auth first + // Also watch for the presence of a `signup` query param, which means + // send the user to sign up flow, not login const url = new URL(request.url); - const redirectTo = url.searchParams.get('from') || ''; - await authClient.login(redirectTo); - - return null; + const redirectTo = url.searchParams.get('from') || '/'; + const isSignupFlow = url.searchParams.get('signup') !== null; + await authClient.login(redirectTo, isSignupFlow); + // auth0 will re-route us (above) but telling react-router where we + // are re-routing to makes sure that this doesn't end up in the history stack + return redirect(redirectTo); }} /> (true); const { permission } = useRecoilValue(editorInteractionStateAtom); const { name, contents } = useFileContext(); + const theme = useTheme(); const submit = useSubmit(); if ((permission === OWNER || permission === EDITOR) && isMobile && isOpen) { @@ -34,15 +35,20 @@ export function PermissionOverlay() { severity="info" sx={{ width: '100%' }} action={ - + + + + } > Welcome to Quadratic. You must log in to edit this file. From 8d30ee92d6a28278d3e01416b4cf70396ac0ad74 Mon Sep 17 00:00:00 2001 From: Jim Nielsen Date: Tue, 12 Sep 2023 18:31:25 -0600 Subject: [PATCH 2/3] Update router.tsx --- src/router.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/router.tsx b/src/router.tsx index 8555dab568..b29bbe2df8 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -133,8 +133,12 @@ export const router = createBrowserRouter( const redirectTo = url.searchParams.get('from') || '/'; const isSignupFlow = url.searchParams.get('signup') !== null; await authClient.login(redirectTo, isSignupFlow); + // auth0 will re-route us (above) but telling react-router where we // are re-routing to makes sure that this doesn't end up in the history stack + // but we have to add an artifical delay that's long enough for + // the auth0 navigation to take place + await new Promise((resolve) => setTimeout(resolve, 10000)); return redirect(redirectTo); }} /> From 56bc685e8cde0fbc04ccfc918b27acbd5cd53632 Mon Sep 17 00:00:00 2001 From: Jim Nielsen Date: Wed, 13 Sep 2023 13:47:37 -0600 Subject: [PATCH 3/3] Update PermissionOverlay.tsx --- src/ui/components/PermissionOverlay.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ui/components/PermissionOverlay.tsx b/src/ui/components/PermissionOverlay.tsx index c770edb3b2..704f2708f2 100644 --- a/src/ui/components/PermissionOverlay.tsx +++ b/src/ui/components/PermissionOverlay.tsx @@ -36,17 +36,17 @@ export function PermissionOverlay() { sx={{ width: '100%' }} action={ - }