aboutsummaryrefslogtreecommitdiffstats
path: root/lib/auth.js
diff options
context:
space:
mode:
authorJohn Barratt <[email protected]>2023-02-28 13:55:59 -0800
committerJohn Barratt <[email protected]>2023-02-28 13:55:59 -0800
commite47d50a443f0a396321716a506e1df325dd4a1fb (patch)
tree1c010c5970e9cbfbf8671e6f00a97d6518446fdd /lib/auth.js
parent58e996a4ac227162f171e84530fe898cb504e045 (diff)
parente4702b4d13e4d966d735c2ba4657e10d7c436a57 (diff)
downloadcoinos-server-e47d50a443f0a396321716a506e1df325dd4a1fb.tar.gz
coinos-server-e47d50a443f0a396321716a506e1df325dd4a1fb.zip
Merge branch 'master' of https://github.com/coinos/coinos-server into notifications
Diffstat (limited to 'lib/auth.js')
-rw-r--r--lib/auth.js20
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/auth.js b/lib/auth.js
index f3cfd1e9..0533de31 100644
--- a/lib/auth.js
+++ b/lib/auth.js
@@ -7,17 +7,17 @@ export const optional = {
preValidation: fastifyPassport.authenticate(
"jwt",
{ session: false },
- function (req, res, err, user, info) {
+ function(req, res, err, user, info) {
req.user = user;
}
- ),
+ )
};
export const auth = {
preValidation: fastifyPassport.authenticate("jwt", {
authInfo: false,
- session: false,
- }),
+ session: false
+ })
};
export const requirePin = async ({ body, user }) => {
@@ -29,13 +29,17 @@ export const jwtStrategy = new jwt.Strategy(
{
jwtFromRequest: jwt.ExtractJwt.fromExtractors([
jwt.ExtractJwt.fromAuthHeaderAsBearerToken(),
- (req) => (req.cookies ? req.cookies.token : null),
+ req => (req.cookies ? req.cookies.token : null)
]),
- secretOrKey: config.jwt,
+ secretOrKey: config.jwt
},
async (payload, next) => {
- let user = await g(`user:${payload.id}`);
- if (typeof user === "string") await g(`user:${user}`);
+ let user;
+ if (payload.id) {
+ user = await g(`user:${payload.id}`);
+ if (typeof user === "string") await g(`user:${user}`);
+ }
+
next(null, user);
}
);