From e7704742ccbe2c121a95e3151f447b79030f8579 Mon Sep 17 00:00:00 2001 From: gpalmer27 Date: Sun, 26 Jan 2025 16:19:32 -0500 Subject: [PATCH 1/8] tried to add check --- apps/auth-proxy/routes/r/[...auth].ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apps/auth-proxy/routes/r/[...auth].ts b/apps/auth-proxy/routes/r/[...auth].ts index 6ab0ad1..a9c6c3f 100644 --- a/apps/auth-proxy/routes/r/[...auth].ts +++ b/apps/auth-proxy/routes/r/[...auth].ts @@ -14,5 +14,17 @@ export default eventHandler(async (event) => clientSecret: process.env.AUTH_GOOGLE_SECRET, }), ], + callbacks: { + async signIn({ user }) { + + const email = user?.email; + console.log("email account: ", email) + + if (!email?.endsWith("@husky.neu.edu")) { + return false; + } + return true; + }, + }, }), ); From ea79496d66cf819fa667ec45c2408293a2ab92a3 Mon Sep 17 00:00:00 2001 From: gpalmer27 Date: Wed, 29 Jan 2025 23:27:05 -0500 Subject: [PATCH 2/8] 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"] } From e4a448a6cb451d03c0dbfdda520d82664c6a8379 Mon Sep 17 00:00:00 2001 From: gpalmer27 Date: Thu, 30 Jan 2025 00:08:09 -0500 Subject: [PATCH 3/8] fixed linting --- packages/auth/src/config.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/auth/src/config.ts b/packages/auth/src/config.ts index 410e845..edd8341 100644 --- a/packages/auth/src/config.ts +++ b/packages/auth/src/config.ts @@ -61,9 +61,10 @@ export const authConfig = { }; }, async signIn({ user }) { - const email = user?.email; + const email = user.email; + const isValid = await email?.endsWith("@husky.neu.edu"); - if (!email?.endsWith("@husky.neu.edu")) { + if (!isValid) { return "/redirection"; } return true; From 30f360ca6cf2ff840a8925321672178ba4e6a412 Mon Sep 17 00:00:00 2001 From: gpalmer27 Date: Thu, 30 Jan 2025 00:10:05 -0500 Subject: [PATCH 4/8] fixed linting --- packages/auth/src/config.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/auth/src/config.ts b/packages/auth/src/config.ts index edd8341..5d2e775 100644 --- a/packages/auth/src/config.ts +++ b/packages/auth/src/config.ts @@ -60,11 +60,10 @@ export const authConfig = { }, }; }, - async signIn({ user }) { + signIn({ user }) { const email = user.email; - const isValid = await email?.endsWith("@husky.neu.edu"); - if (!isValid) { + if (!email?.endsWith("@husky.neu.edu")) { return "/redirection"; } return true; From e8348efd6711dcdf309358eeeb588ae697e0dee5 Mon Sep 17 00:00:00 2001 From: gpalmer27 Date: Thu, 30 Jan 2025 00:14:50 -0500 Subject: [PATCH 5/8] fixed linting --- apps/auth-proxy/routes/r/[...auth].ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/auth-proxy/routes/r/[...auth].ts b/apps/auth-proxy/routes/r/[...auth].ts index ae13825..202cfff 100644 --- a/apps/auth-proxy/routes/r/[...auth].ts +++ b/apps/auth-proxy/routes/r/[...auth].ts @@ -15,8 +15,8 @@ export default eventHandler(async (event) => }), ], callbacks: { - async signIn({ user }) { - const email = user?.email; + signIn({ user }) { + const email = user.email; if (!email?.endsWith("@husky.neu.edu")) { return false; From 20c08654ab22f9b76928aae223fece27d058e7d8 Mon Sep 17 00:00:00 2001 From: gpalmer27 Date: Thu, 30 Jan 2025 17:23:35 -0500 Subject: [PATCH 6/8] updated documentation --- apps/docs/docs/03-backend/auth.mdx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/docs/docs/03-backend/auth.mdx b/apps/docs/docs/03-backend/auth.mdx index 0cc7cac..55c8b58 100644 --- a/apps/docs/docs/03-backend/auth.mdx +++ b/apps/docs/docs/03-backend/auth.mdx @@ -62,7 +62,9 @@ export async function AuthShowcase() { The `auth()` function can only be run on the server side so we currently fetch the session information on the server side and pass it to the client side. In the above example, we make use of form actions to trigger the sign-in and sign-out functions. ::: -One thing that we can hope for is that noone will ever have to work on this code since authentication is always a pain. +:::note +We require users to sign in with their @husky.neu.edu email addresses, and if they try to sign in with something else, they are prompted to sign in again. +::: ### `Session` Type From 068be268ce31ab73fa9ce4cf4219ebe4ef2c64cb Mon Sep 17 00:00:00 2001 From: gpalmer27 Date: Thu, 30 Jan 2025 18:24:25 -0500 Subject: [PATCH 7/8] fixed minor comments --- apps/auth-proxy/routes/r/[...auth].ts | 12 +----------- .../src/app/(pages)/(dashboard)/redirection/page.tsx | 12 ++++++------ packages/auth/tsconfig.json | 3 +-- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/apps/auth-proxy/routes/r/[...auth].ts b/apps/auth-proxy/routes/r/[...auth].ts index 202cfff..7609667 100644 --- a/apps/auth-proxy/routes/r/[...auth].ts +++ b/apps/auth-proxy/routes/r/[...auth].ts @@ -13,16 +13,6 @@ export default eventHandler(async (event) => clientId: process.env.AUTH_GOOGLE_ID, clientSecret: process.env.AUTH_GOOGLE_SECRET, }), - ], - callbacks: { - signIn({ user }) { - const email = user.email; - - if (!email?.endsWith("@husky.neu.edu")) { - 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 index f2d04f6..93f4af1 100644 --- a/apps/web/src/app/(pages)/(dashboard)/redirection/page.tsx +++ b/apps/web/src/app/(pages)/(dashboard)/redirection/page.tsx @@ -1,17 +1,17 @@ -import React from "react"; - export default function ErrorPage() { return ( -
+
+
-

+

Authentication Error

-

You must log in with husky.neu.edu

-

+

You must log in with husky.neu.edu

+

Click the sign in button to try again

+
); } diff --git a/packages/auth/tsconfig.json b/packages/auth/tsconfig.json index cbdebcf..ba38e2a 100644 --- a/packages/auth/tsconfig.json +++ b/packages/auth/tsconfig.json @@ -1,9 +1,8 @@ { "extends": "@cooper/tsconfig/base.json", "compilerOptions": { - "jsx": "react", "tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json" }, - "include": ["src", "*.ts", "../../apps/web/error-page.tsx"], + "include": ["src", "*.ts",], "exclude": ["node_modules"] } From 7ae617c1ffdc769abff8eec2190ace3ea4949357 Mon Sep 17 00:00:00 2001 From: gpalmer27 Date: Thu, 30 Jan 2025 18:28:43 -0500 Subject: [PATCH 8/8] formatting --- apps/auth-proxy/routes/r/[...auth].ts | 2 +- .../(pages)/(dashboard)/redirection/page.tsx | 18 ++++++++---------- packages/auth/tsconfig.json | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/apps/auth-proxy/routes/r/[...auth].ts b/apps/auth-proxy/routes/r/[...auth].ts index 7609667..6ab0ad1 100644 --- a/apps/auth-proxy/routes/r/[...auth].ts +++ b/apps/auth-proxy/routes/r/[...auth].ts @@ -13,6 +13,6 @@ export default eventHandler(async (event) => clientId: process.env.AUTH_GOOGLE_ID, clientSecret: process.env.AUTH_GOOGLE_SECRET, }), - ] + ], }), ); diff --git a/apps/web/src/app/(pages)/(dashboard)/redirection/page.tsx b/apps/web/src/app/(pages)/(dashboard)/redirection/page.tsx index 93f4af1..7239488 100644 --- a/apps/web/src/app/(pages)/(dashboard)/redirection/page.tsx +++ b/apps/web/src/app/(pages)/(dashboard)/redirection/page.tsx @@ -1,17 +1,15 @@ export default function ErrorPage() { return (
-
-
-

- Authentication Error -

-

You must log in with husky.neu.edu

-

- Click the sign in button to try again -

+
+
+

+ Authentication Error +

+

You must log in with husky.neu.edu

+

Click the sign in button to try again

+
-
); } diff --git a/packages/auth/tsconfig.json b/packages/auth/tsconfig.json index ba38e2a..8d4ef63 100644 --- a/packages/auth/tsconfig.json +++ b/packages/auth/tsconfig.json @@ -3,6 +3,6 @@ "compilerOptions": { "tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json" }, - "include": ["src", "*.ts",], + "include": ["src", "*.ts"], "exclude": ["node_modules"] }