forked from tldraw/tldraw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
botcom: redirect to intended room when signing in (tldraw#4725)
also, fixes up the not authenticated/forbidden error msg (was always sending down forbidden accidentally) ### Change type - [ ] `bugfix` - [ ] `improvement` - [ ] `feature` - [ ] `api` - [x] `other`
- Loading branch information
1 parent
9894eb4
commit d1ff2ff
Showing
5 changed files
with
54 additions
and
36 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
apps/dotcom/client/src/components/LoginRedirectPage/LoginRedirectPage.tsx
This file contains 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,25 @@ | ||
import { ClerkProvider, useClerk } from '@clerk/clerk-react' | ||
|
||
export default function LoginRedirectPage() { | ||
// @ts-ignore this is fine | ||
const PUBLISHABLE_KEY = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY | ||
|
||
if (!PUBLISHABLE_KEY) { | ||
throw new Error('Missing VITE_CLERK_PUBLISHABLE_KEY in .env.local') | ||
} | ||
|
||
return ( | ||
<ClerkProvider publishableKey={PUBLISHABLE_KEY}> | ||
<LoginRedirectPageInner /> | ||
</ClerkProvider> | ||
) | ||
} | ||
|
||
function LoginRedirectPageInner() { | ||
const clerk = useClerk() | ||
|
||
const signInUrl = clerk.buildSignInUrl({ signInForceRedirectUrl: window.location.href }) | ||
window.location.href = signInUrl | ||
|
||
return null | ||
} |
This file contains 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 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 |
---|---|---|
|
@@ -6,11 +6,13 @@ import { | |
SNAPSHOT_PREFIX, | ||
} from '@tldraw/dotcom-shared' | ||
import { TLRemoteSyncError, TLSyncErrorCloseEventReason } from '@tldraw/sync-core' | ||
import { useEffect } from 'react' | ||
import { Link, Route, createRoutesFromElements, useRouteError } from 'react-router-dom' | ||
import { Suspense, lazy, useEffect } from 'react' | ||
import { Route, createRoutesFromElements, useRouteError } from 'react-router-dom' | ||
import { DefaultErrorFallback } from './components/DefaultErrorFallback/DefaultErrorFallback' | ||
import { ErrorPage } from './components/ErrorPage/ErrorPage' | ||
|
||
const LoginRedirectPage = lazy(() => import('./components/LoginRedirectPage/LoginRedirectPage')) | ||
|
||
export const router = createRoutesFromElements( | ||
<Route | ||
ErrorBoundary={() => { | ||
|
@@ -19,52 +21,36 @@ export const router = createRoutesFromElements( | |
captureException(error) | ||
}, [error]) | ||
|
||
let header = 'Something went wrong' | ||
let para1 = | ||
'Please try refreshing the page. Still having trouble? Let us know at [email protected].' | ||
if (error instanceof TLRemoteSyncError) { | ||
switch (error.reason) { | ||
case TLSyncErrorCloseEventReason.NOT_FOUND: { | ||
return ( | ||
<ErrorPage | ||
messages={{ | ||
header: 'Not found', | ||
para1: 'The file you are looking for does not exist.', | ||
}} | ||
/> | ||
) | ||
header = 'Not found' | ||
para1 = 'The file you are looking for does not exist.' | ||
break | ||
} | ||
case TLSyncErrorCloseEventReason.NOT_AUTHENTICATED: { | ||
return ( | ||
<ErrorPage | ||
messages={{ | ||
header: 'Unauthorized', | ||
para1: 'You need to be signed in to view this file.', | ||
}} | ||
/> | ||
<Suspense> | ||
<LoginRedirectPage /> | ||
</Suspense> | ||
) | ||
} | ||
case TLSyncErrorCloseEventReason.FORBIDDEN: { | ||
return ( | ||
<ErrorPage | ||
messages={{ | ||
header: 'Unauthorized', | ||
para1: 'You need to be authorized to view this file.', | ||
}} | ||
cta={ | ||
<Link to={'/q'} target={'_self'}> | ||
{'Back to tldraw.'} | ||
</Link> | ||
} | ||
/> | ||
) | ||
header = 'Forbidden' | ||
para1 = 'You are forbidden to view this file.' | ||
break | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<ErrorPage | ||
messages={{ | ||
header: 'Something went wrong', | ||
para1: | ||
'Please try refreshing the page. Still having trouble? Let us know at [email protected].', | ||
header, | ||
para1, | ||
}} | ||
/> | ||
) | ||
|
This file contains 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 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