enables refresh route to safely update httpOnly cookie

This commit is contained in:
James
2020-07-03 13:15:56 -04:00
parent e904402eff
commit a4ef486e1a
3 changed files with 6 additions and 2 deletions

View File

@@ -21,7 +21,7 @@ const refresh = async (args) => {
// 2. Perform refresh
// /////////////////////////////////////
const { secret } = options.config;
const { secret, cookiePrefix } = options.config;
const opts = {};
opts.expiresIn = options.collection.config.auth.tokenExpiration;
@@ -33,6 +33,10 @@ const refresh = async (args) => {
delete payload.exp;
const refreshedToken = jwt.sign(payload, secret, opts);
if (args.res) {
args.res.cookie(`${cookiePrefix}-token`, refreshedToken, { path: '/', httpOnly: true });
}
// /////////////////////////////////////
// 3. Execute after login hook
// /////////////////////////////////////

View File

@@ -6,6 +6,7 @@ const refreshHandler = config => async (req, res) => {
try {
const result = await refresh({
req,
res,
collection: req.collection,
config,
authorization: req.headers.authorization,