Skip to content

Commit 4e6c749

Browse files
committed
make customizable also the redirect view
1 parent 4b5f9ac commit 4e6c749

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/index.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ import jwtDecode from 'jwt-decode';
22

33
const applyConfig = (config) => {
44
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;
58

6-
const loginUrl = prefixPath ? `${prefixPath}/login` : '/login';
9+
const loginUrl = prefixPath
10+
? `${prefixPath}${redirectUrl}`
11+
: `/${redirectUrl}`;
712
const excludeUrls = prefixPath
8-
? `^\\/static|^\\${prefixPath}\\/login`
9-
: '^/static|^/login';
13+
? `^\\/static|^\\${prefixPath}\\${redirectUrl}`
14+
: `^\\/static|^\\${redirectUrl}`;
1015

1116
const defaults = {
1217
rejectanonymousSettings: {
@@ -20,8 +25,6 @@ const applyConfig = (config) => {
2025
...defaults,
2126
};
2227

23-
const enabled = process.env.RAZZLE_REJECT_ANONYMOUS || false;
24-
2528
if (__SERVER__ && enabled) {
2629
const express = require('express');
2730
const middleware = express.Router();
@@ -33,10 +36,6 @@ const applyConfig = (config) => {
3336
// TODO: anzichè redirect potrebbe essere settato un nuovo cookie di
3437
// autenticazione con un token valido per l'utente
3538
if (!token) {
36-
console.log(
37-
'mando qui: ',
38-
`${settings.loginUrl}?came_from=${req.url}`,
39-
);
4039
return res.redirect(`${settings.loginUrl}?came_from=${req.url}`);
4140
}
4241
if (token && settings?.userHeaderName) {

0 commit comments

Comments
 (0)