mirror of
https://github.com/plankanban/planka.git
synced 2025-12-28 17:24:59 +03:00
feat: Store accessToken in cookies instead of localStorage
This commit is contained in:
@@ -34,11 +34,16 @@ module.exports = function defineCurrentUserHook(sails) {
|
||||
before: {
|
||||
'/*': {
|
||||
async fn(req, res, next) {
|
||||
const { authorization: authorizationHeader } = req.headers;
|
||||
|
||||
if (authorizationHeader && TOKEN_PATTERN.test(authorizationHeader)) {
|
||||
const accessToken = authorizationHeader.replace(TOKEN_PATTERN, '');
|
||||
let accessToken;
|
||||
if (req.headers.authorization) {
|
||||
if (TOKEN_PATTERN.test(req.headers.authorization)) {
|
||||
accessToken = req.headers.authorization.replace(TOKEN_PATTERN, '');
|
||||
}
|
||||
} else if (req.cookies.accessToken) {
|
||||
accessToken = req.cookies.accessToken;
|
||||
}
|
||||
|
||||
if (accessToken) {
|
||||
req.currentUser = await getUser(accessToken);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ module.exports.security = {
|
||||
allRoutes: true,
|
||||
allowOrigins: ['http://localhost:3000'],
|
||||
allowRequestHeaders: ['Authorization'],
|
||||
allowCredentials: false,
|
||||
allowCredentials: true,
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user