Skip to content

Commit 4b5f9ac

Browse files
committed
make customizable
1 parent 7e4e2d4 commit 4b5f9ac

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/index.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
import jwtDecode from 'jwt-decode';
22

33
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+
411
const defaults = {
512
rejectanonymousSettings: {
613
userHeaderName: 'REMOTE_USER',
7-
loginUrl: '/login',
8-
excludeUrls: /^\/static|^\/login/,
14+
loginUrl,
15+
excludeUrls: new RegExp(excludeUrls),
916
},
1017
};
1118
config.settings = {
1219
...config.settings,
1320
...defaults,
1421
};
15-
if (__SERVER__) {
22+
23+
const enabled = process.env.RAZZLE_REJECT_ANONYMOUS || false;
24+
25+
if (__SERVER__ && enabled) {
1626
const express = require('express');
1727
const middleware = express.Router();
1828
const settings = config.settings.rejectanonymousSettings;
@@ -23,6 +33,10 @@ const applyConfig = (config) => {
2333
// TODO: anzichè redirect potrebbe essere settato un nuovo cookie di
2434
// autenticazione con un token valido per l'utente
2535
if (!token) {
36+
console.log(
37+
'mando qui: ',
38+
`${settings.loginUrl}?came_from=${req.url}`,
39+
);
2640
return res.redirect(`${settings.loginUrl}?came_from=${req.url}`);
2741
}
2842
if (token && settings?.userHeaderName) {

0 commit comments

Comments
 (0)