aboutsummaryrefslogtreecommitdiffstats
path: root/lib/passport.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-01-16 23:40:25 -0800
committerAdam Soltys <[email protected]>2023-01-16 23:40:25 -0800
commit91e847126c832efa25ab0bf8d6f3b7e537378fa7 (patch)
tree4a42b6e3bec6eb0f640ed44533b54e6d3d6a5e0e /lib/passport.js
parent6bafea9bffe24d2227d269812a73a9a513d92ddf (diff)
downloadcoinos-server-91e847126c832efa25ab0bf8d6f3b7e537378fa7.tar.gz
coinos-server-91e847126c832efa25ab0bf8d6f3b7e537378fa7.zip
shuffle things around
Diffstat (limited to 'lib/passport.js')
-rw-r--r--lib/passport.js79
1 files changed, 0 insertions, 79 deletions
diff --git a/lib/passport.js b/lib/passport.js
deleted file mode 100644
index 25dc0103..00000000
--- a/lib/passport.js
+++ /dev/null
@@ -1,79 +0,0 @@
-import app from "$app";
-import jwt from "passport-jwt";
-import fastifyPassport from "@fastify/passport";
-import fastifySecureSession from "@fastify/secure-session";
-import config from "$config";
-import fs from "fs";
-import path from "path";
-import { err } from "$lib/logging";
-import { g } from "$lib/redis";
-
-app.register(fastifySecureSession, {
- key: Buffer.from(config.jwt, "hex")
-});
-
-app.register(fastifyPassport.initialize());
-app.register(fastifyPassport.secureSession());
-
-function cookieExtractor(req) {
- if (req && req.cookies) {
- return req.cookies["token"];
- }
- return null;
-}
-
-fastifyPassport.use(
- "jwt",
- new jwt.Strategy(
- {
- jwtFromRequest: jwt.ExtractJwt.fromExtractors([
- jwt.ExtractJwt.fromAuthHeaderAsBearerToken(),
- cookieExtractor
- ]),
- secretOrKey: config.jwt
- },
- async (payload, next) => {
- try {
- let { id } = payload;
- let user = await g(`user:${id}`);
- user.haspin = !!user.pin;
- next(null, user);
- } catch (e) {
- console.log("payload", payload);
- if (!e.message.includes("locked")) {
- console.log(e);
- err("problem logging in", e);
- }
- next(null, { username: "guest" });
- }
- }
- )
-);
-
-export const optionalAuth = {
- preValidation: fastifyPassport.authenticate(
- "jwt",
- { session: false },
- function(req, res, err, user, info) {
- req.user = user;
- }
- )
-};
-
-export const adminAuth = {
- preValidation: fastifyPassport.authenticate(
- "jwt",
- { session: false },
- function(req, res, err, user, info) {
- if (!(user && user.admin)) return res.code(401).send("Unauthorized");
- req.user = user;
- }
- )
-};
-
-export const auth = {
- preValidation: fastifyPassport.authenticate("jwt", {
- authInfo: false,
- session: false
- })
-};