From 0cc30baa2ee4ad110d3d026f7b75fe60b77680eb Mon Sep 17 00:00:00 2001 From: Aydan Pirani Date: Mon, 14 Aug 2023 00:05:01 -0700 Subject: [PATCH] Final changes to auth login setup --- api/services/auth/auth-lib.ts | 4 +--- api/services/auth/auth-router.ts | 10 +++++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/api/services/auth/auth-lib.ts b/api/services/auth/auth-lib.ts index c271506f..97156e0c 100644 --- a/api/services/auth/auth-lib.ts +++ b/api/services/auth/auth-lib.ts @@ -54,7 +54,6 @@ export function generateJwtToken(payload: JwtPayload): string { } const options: SignOptions = { - // algorithm: "ES256", expiresIn: "7d", }; @@ -62,6 +61,7 @@ export function generateJwtToken(payload: JwtPayload): string { return token; } + export function initializeRoles(provider: Provider): Role[] { const roles: Role[] = []; @@ -74,13 +74,11 @@ export function initializeRoles(provider: Provider): Role[] { export async function getRoles(id: string, provider: Provider): Promise { const collection: Collection = await DatabaseHelper.getCollection("auth", "roles"); - console.log("in get roles! %s", id); let roles: Role[] = []; try { const userRoles: RolesSchema | null = await collection.findOne({ id: id }) as RolesSchema | null; if (userRoles == null) { - console.log("user not found! inserting"); roles = initializeRoles(provider); const newUser: RolesSchema = { _id: new ObjectId(), id: id, provider: provider, roles: roles }; const insertResult: InsertOneResult = await collection.insertOne(newUser); diff --git a/api/services/auth/auth-router.ts b/api/services/auth/auth-router.ts index daf0e3d0..1a48ac69 100644 --- a/api/services/auth/auth-router.ts +++ b/api/services/auth/auth-router.ts @@ -1,27 +1,27 @@ import "dotenv"; -import express, { Request, Response, Router } from "express"; import passport from "passport"; +import { NextFunction } from "express-serve-static-core"; +import express, { Request, Response, Router } from "express"; import GitHubStrategy, { Profile as GithubProfile } from "passport-github"; import { Profile as GoogleProfile, Strategy as GoogleStrategy } from "passport-google-oauth20"; import Constants from "../../constants.js"; import { SelectAuthProvider } from "../../middleware/select-auth.js"; -import { generateJwtToken as generateJwtToken, getJwtPayload, verifyFunction } from "./auth-lib.js"; import { JwtPayload, ProfileData, Provider } from "./auth-models.js"; -import { NextFunction } from "express-serve-static-core"; +import { generateJwtToken as generateJwtToken, getJwtPayload, verifyFunction } from "./auth-lib.js"; passport.use(Provider.GITHUB, new GitHubStrategy({ clientID: process.env.GITHUB_OAUTH_ID ?? "", clientSecret: process.env.GITHUB_OAUTH_SECRET ?? "", - callbackURL: Constants.OAUTH_CALLBACK, + callbackURL: Constants.GITHUB_OAUTH_CALLBACK, }, verifyFunction)); passport.use(Provider.GOOGLE, new GoogleStrategy({ clientID: process.env.GOOGLE_OAUTH_ID ?? "", clientSecret: process.env.GOOGLE_OAUTH_SECRET ?? "", - callbackURL: Constants.OAUTH_CALLBACK, + callbackURL: Constants.GOOGLE_OAUTH_CALLBACK, }, verifyFunction));