File tree Expand file tree Collapse file tree 6 files changed +47
-44
lines changed
frontend/apps/impress/src Expand file tree Collapse file tree 6 files changed +47
-44
lines changed Original file line number Diff line number Diff line change @@ -551,6 +551,9 @@ class Base(Configuration):
551
551
environ_name = "OIDC_STORE_REFRESH_TOKEN_KEY" ,
552
552
environ_prefix = None ,
553
553
)
554
+ OIDC_REDIRECT_FIELD_NAME = values .Value (
555
+ "returnTo" , environ_name = "OIDC_REDIRECT_FIELD_NAME" , environ_prefix = None
556
+ )
554
557
555
558
# WARNING: Enabling this setting allows multiple user accounts to share the same email
556
559
# address. This may cause security issues and is not recommended for production use when
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { useRouter } from 'next/router';
4
4
import { useEffect } from 'react' ;
5
5
6
6
import { useCunninghamTheme } from '@/cunningham' ;
7
- import { Auth , KEY_AUTH , setAuthUrl } from '@/features/auth' ;
7
+ import { Auth , KEY_AUTH } from '@/features/auth' ;
8
8
import { useResponsiveStore } from '@/stores/' ;
9
9
10
10
import { ConfigProvider } from './config/' ;
@@ -51,8 +51,9 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
51
51
void queryClient . resetQueries ( {
52
52
queryKey : [ KEY_AUTH ] ,
53
53
} ) ;
54
- setAuthUrl ( ) ;
55
- void replace ( `/401` ) ;
54
+ void replace (
55
+ `/401?returnTo=${ encodeURIComponent ( window . location . pathname ) } ` ,
56
+ ) ;
56
57
}
57
58
} ,
58
59
} ,
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import { useConfig } from '@/core';
7
7
8
8
import { HOME_URL } from '../conf' ;
9
9
import { useAuth } from '../hooks' ;
10
- import { getAuthUrl , gotoLogin } from '../utils' ;
10
+ import { gotoLogin } from '../utils' ;
11
11
12
12
export const Auth = ( { children } : PropsWithChildren ) => {
13
13
const { isLoading, pathAllowed, isFetchedAfterMount, authenticated } =
@@ -23,21 +23,22 @@ export const Auth = ({ children }: PropsWithChildren) => {
23
23
) ;
24
24
}
25
25
26
+ // todo - clarify this trick.
26
27
/**
27
- * If the user is authenticated and wanted initially to access a document,
28
- * we redirect to the document page.
29
- */
30
- if ( authenticated ) {
31
- const authUrl = getAuthUrl ( ) ;
32
- if ( authUrl ) {
33
- void replace ( authUrl ) ;
34
- return (
35
- < Box $height = "100vh" $width = "100vw" $align = "center" $justify = "center" >
36
- < Loader />
37
- </ Box >
38
- ) ;
39
- }
40
- }
28
+ // * If the user is authenticated and wanted initially to access a document,
29
+ // * we redirect to the document page.
30
+ // */
31
+ // if (authenticated) {
32
+ // const authUrl = getAuthUrl();
33
+ // if (authUrl) {
34
+ // void replace(authUrl);
35
+ // return (
36
+ // <Box $height="100vh" $width="100vw" $align="center" $justify="center">
37
+ // <Loader />
38
+ // </Box>
39
+ // );
40
+ // }
41
+ // }
41
42
42
43
/**
43
44
* If the user is not authenticated and the path is not allowed, we redirect to the login page.
Original file line number Diff line number Diff line change 1
1
import { terminateCrispSession } from '@/services/Crisp' ;
2
2
3
- import { LOGIN_URL , LOGOUT_URL , PATH_AUTH_LOCAL_STORAGE } from './conf' ;
3
+ import { LOGIN_URL , LOGOUT_URL } from './conf' ;
4
+ import { backendUrl } from "@/api" ;
4
5
5
- export const getAuthUrl = ( ) => {
6
- const path_auth = localStorage . getItem ( PATH_AUTH_LOCAL_STORAGE ) ;
7
- if ( path_auth ) {
8
- localStorage . removeItem ( PATH_AUTH_LOCAL_STORAGE ) ;
9
- return path_auth ;
10
- }
11
- } ;
12
-
13
- export const setAuthUrl = ( ) => {
14
- if ( window . location . pathname !== '/' ) {
15
- localStorage . setItem ( PATH_AUTH_LOCAL_STORAGE , window . location . pathname ) ;
16
- }
17
- } ;
18
-
19
- export const gotoLogin = ( withRedirect = true ) => {
20
- if ( withRedirect ) {
21
- setAuthUrl ( ) ;
22
- }
23
6
24
- window . location . replace ( LOGIN_URL ) ;
7
+ export const gotoLogin = ( returnTo = '/' ) => {
8
+ const authenticateUrl = LOGIN_URL + `?returnTo=${ backendUrl ( ) + returnTo } `
9
+ window . location . replace ( authenticateUrl ) ;
25
10
} ;
26
11
27
12
export const gotoLogout = ( ) => {
Original file line number Diff line number Diff line change 1
1
import { Button } from '@openfun/cunningham-react' ;
2
2
import Image from 'next/image' ;
3
3
import { useRouter } from 'next/router' ;
4
- import { ReactElement , useEffect } from 'react' ;
4
+ import { ReactElement , useEffect , useState } from 'react' ;
5
5
import { useTranslation } from 'react-i18next' ;
6
6
7
7
import img401 from '@/assets/icons/icon-401.png' ;
@@ -13,7 +13,19 @@ import { NextPageWithLayout } from '@/types/next';
13
13
const Page : NextPageWithLayout = ( ) => {
14
14
const { t } = useTranslation ( ) ;
15
15
const { authenticated } = useAuth ( ) ;
16
- const { replace } = useRouter ( ) ;
16
+ const router = useRouter ( ) ;
17
+ const { replace } = router ;
18
+
19
+ const [ returnTo , setReturnTo ] = useState < string | undefined > ( undefined )
20
+ const { returnTo : returnToParams } = router . query ;
21
+
22
+
23
+ useEffect ( ( ) => {
24
+ if ( returnToParams ) {
25
+ setReturnTo ( returnToParams as string )
26
+ void replace ( '/401' )
27
+ }
28
+ } , [ returnToParams ] ) ;
17
29
18
30
useEffect ( ( ) => {
19
31
if ( authenticated ) {
@@ -42,7 +54,7 @@ const Page: NextPageWithLayout = () => {
42
54
{ t ( 'Log in to access the document.' ) }
43
55
</ Text >
44
56
45
- < Button onClick = { ( ) => gotoLogin ( false ) } aria-label = { t ( 'Login' ) } >
57
+ < Button onClick = { ( ) => gotoLogin ( returnTo ) } aria-label = { t ( 'Login' ) } >
46
58
{ t ( 'Login' ) }
47
59
</ Button >
48
60
</ Box >
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import {
14
14
useDoc ,
15
15
useDocStore ,
16
16
} from '@/docs/doc-management/' ;
17
- import { KEY_AUTH , setAuthUrl } from '@/features/auth' ;
17
+ import { KEY_AUTH } from '@/features/auth' ;
18
18
import { MainLayout } from '@/layouts' ;
19
19
import { useBroadcastStore } from '@/stores' ;
20
20
import { NextPageWithLayout } from '@/types/next' ;
@@ -115,8 +115,9 @@ const DocPage = ({ id }: DocProps) => {
115
115
void queryClient . resetQueries ( {
116
116
queryKey : [ KEY_AUTH ] ,
117
117
} ) ;
118
- setAuthUrl ( ) ;
119
- void replace ( `/401` ) ;
118
+ void replace (
119
+ `/401?returnTo=${ encodeURIComponent ( window . location . pathname ) } ` ,
120
+ ) ;
120
121
return null ;
121
122
}
122
123
You can’t perform that action at this time.
0 commit comments