File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change 1
1
import jwtDecode from 'jwt-decode' ;
2
2
3
3
const applyConfig = ( config ) => {
4
+ const { prefixPath } = config . settings ;
5
+
6
+ const loginUrl = prefixPath ? `${ prefixPath } /login` : '/login' ;
7
+ const excludeUrls = prefixPath
8
+ ? `^\\/static|^\\${ prefixPath } \\/login`
9
+ : '^/static|^/login' ;
10
+
4
11
const defaults = {
5
12
rejectanonymousSettings : {
6
13
userHeaderName : 'REMOTE_USER' ,
7
- loginUrl : '/login' ,
8
- excludeUrls : / ^ \/ s t a t i c | ^ \/ l o g i n / ,
14
+ loginUrl,
15
+ excludeUrls : new RegExp ( excludeUrls ) ,
9
16
} ,
10
17
} ;
11
18
config . settings = {
12
19
...config . settings ,
13
20
...defaults ,
14
21
} ;
15
- if ( __SERVER__ ) {
22
+
23
+ const enabled = process . env . RAZZLE_REJECT_ANONYMOUS || false ;
24
+
25
+ if ( __SERVER__ && enabled ) {
16
26
const express = require ( 'express' ) ;
17
27
const middleware = express . Router ( ) ;
18
28
const settings = config . settings . rejectanonymousSettings ;
@@ -23,6 +33,10 @@ const applyConfig = (config) => {
23
33
// TODO: anzichè redirect potrebbe essere settato un nuovo cookie di
24
34
// autenticazione con un token valido per l'utente
25
35
if ( ! token ) {
36
+ console . log (
37
+ 'mando qui: ' ,
38
+ `${ settings . loginUrl } ?came_from=${ req . url } ` ,
39
+ ) ;
26
40
return res . redirect ( `${ settings . loginUrl } ?came_from=${ req . url } ` ) ;
27
41
}
28
42
if ( token && settings ?. userHeaderName ) {
You can’t perform that action at this time.
0 commit comments