@@ -2,11 +2,16 @@ import jwtDecode from 'jwt-decode';
2
2
3
3
const applyConfig = ( config ) => {
4
4
const { prefixPath } = config . settings ;
5
+ const redirectUrl =
6
+ process . env . RAZZLE_REJECT_ANONYMOUS_REDIRECT_URL || '/login' ;
7
+ const enabled = process . env . RAZZLE_REJECT_ANONYMOUS || false ;
5
8
6
- const loginUrl = prefixPath ? `${ prefixPath } /login` : '/login' ;
9
+ const loginUrl = prefixPath
10
+ ? `${ prefixPath } ${ redirectUrl } `
11
+ : `/${ redirectUrl } ` ;
7
12
const excludeUrls = prefixPath
8
- ? `^\\/static|^\\${ prefixPath } \\/login `
9
- : '^ /static|^/login' ;
13
+ ? `^\\/static|^\\${ prefixPath } \\${ redirectUrl } `
14
+ : `^\\ /static|^\\ ${ redirectUrl } ` ;
10
15
11
16
const defaults = {
12
17
rejectanonymousSettings : {
@@ -20,8 +25,6 @@ const applyConfig = (config) => {
20
25
...defaults ,
21
26
} ;
22
27
23
- const enabled = process . env . RAZZLE_REJECT_ANONYMOUS || false ;
24
-
25
28
if ( __SERVER__ && enabled ) {
26
29
const express = require ( 'express' ) ;
27
30
const middleware = express . Router ( ) ;
@@ -33,10 +36,6 @@ const applyConfig = (config) => {
33
36
// TODO: anzichè redirect potrebbe essere settato un nuovo cookie di
34
37
// autenticazione con un token valido per l'utente
35
38
if ( ! token ) {
36
- console . log (
37
- 'mando qui: ' ,
38
- `${ settings . loginUrl } ?came_from=${ req . url } ` ,
39
- ) ;
40
39
return res . redirect ( `${ settings . loginUrl } ?came_from=${ req . url } ` ) ;
41
40
}
42
41
if ( token && settings ?. userHeaderName ) {
0 commit comments