1- import { useState } from 'react' ;
1+ import { useEffect , useState } from 'react' ;
2+ import { useLocation } from 'react-router-dom' ;
23import { authenticationUrl } from '@api/auth' ;
34import { useQueryDemoSiteStatus } from '@queries/demo-site-status' ;
45import { urls } from 'configs' ;
6+ import { setCookieState } from 'cookie' ;
57import { useSubmit } from 'hooks' ;
68import { useTranslation } from 'i18n' ;
9+ import queryString from 'query-string' ;
710import { cn } from 'utils/style' ;
811import { IconGoogle } from '@icons' ;
912import AuthWrapper from 'pages/signin/elements/auth-wrapper' ;
@@ -13,19 +16,23 @@ import FormLoading from 'elements/form-loading';
1316import DemoForm from './demo-form' ;
1417
1518const AccessDemoPage = ( ) => {
16- const { t } = useTranslation ( [ 'auth' , 'common' , 'form' , 'message' ] ) ;
19+ const { t } = useTranslation ( [ 'common' , 'auth' , 'message' ] ) ;
20+ const location = useLocation ( ) ;
21+ const query = location . search ;
1722
23+ const [ userToken , setUserToken ] = useState ( '' ) ;
1824 const { data : demoSiteStatusData , isLoading } = useQueryDemoSiteStatus ( ) ;
19- const isDemoSiteEnabled = ! demoSiteStatusData ?. isDemoSiteEnabled ;
2025
21- const [ isAuthenticated ] = useState ( false ) ;
26+ const isDemoSiteEnabled = demoSiteStatusData ?. isDemoSiteEnabled ;
27+ const isAuthenticated = Boolean ( userToken ) ;
2228
2329 const { onSubmit : onGoogleLoginHandler , submitting } = useSubmit ( ( ) => {
2430 const state = `${ Date . now ( ) } ` ;
31+ setCookieState ( state ) ;
2532
2633 return authenticationUrl ( {
2734 state,
28- redirectUrl : urls . AUTH_REDIRECT ,
35+ redirectUrl : urls . AUTH_DEMO_REDIRECT ,
2936 type : 2 // Google auth type
3037 } ) . then ( response => {
3138 if ( response . url ) {
@@ -34,14 +41,21 @@ const AccessDemoPage = () => {
3441 } ) ;
3542 } ) ;
3643
44+ useEffect ( ( ) => {
45+ const { token } = queryString . parse ( query ) ;
46+ if ( token && typeof token === 'string' ) {
47+ setUserToken ( token ) ;
48+ }
49+ } , [ query ] ) ;
50+
3751 return (
3852 < AuthWrapper >
3953 { isLoading ? (
4054 < FormLoading />
4155 ) : (
4256 < >
4357 < h1 className = "text-gray-900 typo-head-bold-huge" >
44- { t ( isAuthenticated ? 'privacy-notice' : 'demo' ) }
58+ { t ( isAuthenticated ? 'auth: privacy-notice' : 'auth: demo' ) }
4559 </ h1 >
4660 < div
4761 className = { cn ( 'text-gray-600 typo-para-medium mt-6' , {
0 commit comments