Skip to content

Commit

Permalink
Merge pull request #72 from ReflectionsProjections/dev/aydan/api-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AydanPirani authored May 29, 2024
2 parents 7ac0a43 + cee2182 commit 526e7df
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ export const Config = {
AUTH_CALLBACK_URI_BASE:
"https://api.reflectionsprojections.org/auth/callback/",

AUTH_ADMIN_WHITELIST: new Set([
"[email protected]", // Aydan Pirani (Dev)
"[email protected]", // Divya Koya (Dev)
"[email protected]", // Aryan Bahl (Dev)
"[email protected]", // Alex Yang (Dev)
"[email protected]", // Aryan Bhardwaj (Dev)
"[email protected]", // Dev Patel (Dev)
"[email protected]", // Divya Koya (Dev)
"[email protected]", // Jacob Chang (Dev)
"[email protected]", // Jeremy Wu (Dev)
"[email protected]", // Manya Dua (Dev)
"[email protected]", // Riya Patel (Dev)
"[email protected]", // Ronit Anandani (Dev)
"[email protected]", // Shreenija Reddy Daggavolu (Dev)
]),

JWT_SIGNING_SECRET: getEnv("JWT_SIGNING_SECRET"),
JWT_EXPIRATION_TIME: "1 day",

Expand Down
6 changes: 4 additions & 2 deletions src/database.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mongoose, { Schema } from "mongoose";
import mongoose, { Schema, Document } from "mongoose";
import {
AttendeeSchema,
AttendeeValidator,
Expand Down Expand Up @@ -43,7 +43,9 @@ function initializeModel(
},
});

return mongoose.model(modelName, schema);
type objectType = Zod.infer<typeof object>;
interface modelType extends Document, objectType {}
return mongoose.model<modelType>(modelName, schema);
}

// Example usage
Expand Down
9 changes: 8 additions & 1 deletion src/services/auth/auth-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { Strategy as GoogleStrategy } from "passport-google-oauth20";
import { Config } from "../../config";
import { Database } from "../../database";
import { Role } from "./auth-models";

export function createGoogleStrategy(device: string) {
return new GoogleStrategy(
Expand All @@ -16,10 +17,16 @@ export function createGoogleStrategy(device: string) {
const userId = `user${profile.id}`;
const name = profile.displayName;
const email = profile._json.email;
const roles = [];

// Check if user is admin -> if so, add ADMIN role to their list
if (Config.AUTH_ADMIN_WHITELIST.has(email ?? "")) {
roles.push(Role.Enum.ADMIN);
}

Database.ROLES.findOneAndUpdate(
{ userId: userId },
{ userId, name, email },
{ userId, name, email, roles },
{ upsert: true }
)
.then(() => cb(null, profile))
Expand Down

0 comments on commit 526e7df

Please sign in to comment.