Skip to content

Commit

Permalink
feat(signin): check for authorization in sign in
Browse files Browse the repository at this point in the history
  • Loading branch information
estarossa0 committed Dec 16, 2021
1 parent 4293c2b commit a9e536f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/lib/staffLogins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const staffLogins = [
"adnan",
"yassin",
"giuseppe",
"charifa",
"hasnaa",
"ef-zed",
"lahsen",
"amine",
"hanane",
"ybouthir",
"scar",
"hind",
"mystic",
"q-beast",
"spoody",
"toxiic",
"sopu",
"hajar",
"mahjoub",
"larbi",
];

export { staffLogins as default };
19 changes: 17 additions & 2 deletions src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import FortyTwoProvider, {
} from "next-auth/providers/42-school";
import prisma from "../../../lib/prisma/client";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import staffLogins from "../../../lib/staffLogins";

export interface authUser {
id: string;
Expand Down Expand Up @@ -32,8 +33,22 @@ export default NextAuth({
}),
],
callbacks: {
async signIn() {
return true;
async signIn({ profile: profileWithNoType }) {
const profile: FortyTwoProfile = profileWithNoType as any;

const isStaff = staffLogins.some(
(staffLogin) => profile.login === staffLogin,
);

if (isStaff) return true;

const fromBgOrKH = profile.campus.some(
(campus) => campus.id === 16 || campus.id === 21,
);

if (fromBgOrKH) return true;

return false;
},
async redirect({ url, baseUrl }) {
if (url.startsWith(baseUrl)) return url;
Expand Down

0 comments on commit a9e536f

Please sign in to comment.