11import { ClientError } from '@sanity/client'
2+ import { SDK_CHANNEL_NAME , SDK_NODE_NAME } from '@sanity/message-protocol'
23import {
34 AuthStateType ,
45 getClientErrorApiBody ,
@@ -10,6 +11,8 @@ import {type FallbackProps} from 'react-error-boundary'
1011
1112import { useAuthState } from '../../hooks/auth/useAuthState'
1213import { useLogOut } from '../../hooks/auth/useLogOut'
14+ import { useWindowConnection } from '../../hooks/comlink/useWindowConnection'
15+ import { useSanityInstance } from '../../hooks/context/useSanityInstance'
1316import { Error } from '../errors/Error'
1417import { AuthError } from './AuthError'
1518import { ConfigurationError } from './ConfigurationError'
@@ -36,12 +39,23 @@ export function LoginError({error, resetErrorBoundary}: LoginErrorProps): React.
3639
3740 const logout = useLogOut ( )
3841 const authState = useAuthState ( )
42+ const {
43+ config : { projectId} ,
44+ } = useSanityInstance ( )
3945
4046 const [ authErrorMessage , setAuthErrorMessage ] = useState (
4147 'Please try again or contact support if the problem persists.' ,
4248 )
4349 const [ showRetryCta , setShowRetryCta ] = useState ( true )
4450
51+ /**
52+ * TODO: before merge update message-protocol package to include the new message type
53+ */
54+ const { fetch} = useWindowConnection ( {
55+ name : SDK_NODE_NAME ,
56+ connectTo : SDK_CHANNEL_NAME ,
57+ } )
58+
4559 const handleRetry = useCallback ( async ( ) => {
4660 await logout ( )
4761 resetErrorBoundary ( )
@@ -55,6 +69,13 @@ export function LoginError({error, resetErrorBoundary}: LoginErrorProps): React.
5569 const description = getClientErrorApiDescription ( error )
5670 if ( description ) setAuthErrorMessage ( description )
5771 setShowRetryCta ( false )
72+ /**
73+ * Handoff to dashboard to enable the request access flow for the project.
74+ */
75+ fetch ( 'dashboard/v1/auth/access/request' , {
76+ resourceType : 'project' ,
77+ resourceId : projectId ,
78+ } )
5879 } else {
5980 setShowRetryCta ( true )
6081 handleRetry ( )
@@ -73,7 +94,7 @@ export function LoginError({error, resetErrorBoundary}: LoginErrorProps): React.
7394 setAuthErrorMessage ( error . message )
7495 setShowRetryCta ( true )
7596 }
76- } , [ authState , handleRetry , error ] )
97+ } , [ authState , handleRetry , error , fetch , projectId ] )
7798
7899 return (
79100 < Error
0 commit comments