From ea79496d66cf819fa667ec45c2408293a2ab92a3 Mon Sep 17 00:00:00 2001 From: gpalmer27 Date: Wed, 29 Jan 2025 23:27:05 -0500 Subject: [PATCH] added redirection page --- apps/auth-proxy/routes/r/[...auth].ts | 4 +--- .../app/(pages)/(dashboard)/redirection/page.tsx | 15 +++++++++++++++ packages/auth/src/config.ts | 8 ++++++++ packages/auth/tsconfig.json | 3 ++- 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 apps/web/src/app/(pages)/(dashboard)/redirection/page.tsx diff --git a/apps/auth-proxy/routes/r/[...auth].ts b/apps/auth-proxy/routes/r/[...auth].ts index a9c6c3f..bb57830 100644 --- a/apps/auth-proxy/routes/r/[...auth].ts +++ b/apps/auth-proxy/routes/r/[...auth].ts @@ -16,12 +16,10 @@ export default eventHandler(async (event) => ], callbacks: { async signIn({ user }) { - const email = user?.email; - console.log("email account: ", email) if (!email?.endsWith("@husky.neu.edu")) { - return false; + return false } return true; }, diff --git a/apps/web/src/app/(pages)/(dashboard)/redirection/page.tsx b/apps/web/src/app/(pages)/(dashboard)/redirection/page.tsx new file mode 100644 index 0000000..b40ad36 --- /dev/null +++ b/apps/web/src/app/(pages)/(dashboard)/redirection/page.tsx @@ -0,0 +1,15 @@ +import React from "react"; + +export default function ErrorPage() { + + return ( +
+
+

Authentication Error

+

You must log in with husky.neu.edu

+

Click the sign in button to try again

+
+
+ ); +} + \ No newline at end of file diff --git a/packages/auth/src/config.ts b/packages/auth/src/config.ts index c6afc0a..be11247 100644 --- a/packages/auth/src/config.ts +++ b/packages/auth/src/config.ts @@ -60,6 +60,14 @@ export const authConfig = { }, }; }, + async signIn({ user }) { + const email = user?.email; + + if (!email?.endsWith("@husky.neu.edu")) { + return '/redirection' + } + return true; + }, }, } satisfies NextAuthConfig; diff --git a/packages/auth/tsconfig.json b/packages/auth/tsconfig.json index 8d4ef63..cbdebcf 100644 --- a/packages/auth/tsconfig.json +++ b/packages/auth/tsconfig.json @@ -1,8 +1,9 @@ { "extends": "@cooper/tsconfig/base.json", "compilerOptions": { + "jsx": "react", "tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json" }, - "include": ["src", "*.ts"], + "include": ["src", "*.ts", "../../apps/web/error-page.tsx"], "exclude": ["node_modules"] }