From ba6530bc9cee73d983a490a8fd3acacddb967448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=B8vring?= Date: Tue, 30 Jul 2024 08:47:57 +0200 Subject: [PATCH 01/10] Reduces exported auth types --- src/app/api/auth/[...nextauth]/route.ts | 4 ++-- src/common/session/AuthjsSession.ts | 12 +++++------- src/composition.ts | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts index 1d38a1d9..85cc4d25 100644 --- a/src/app/api/auth/[...nextauth]/route.ts +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -1,3 +1,3 @@ -import { auth } from "@/composition" +import { authHandlers } from "@/composition" -export const { GET, POST } = auth.handlers +export const { GET, POST } = authHandlers diff --git a/src/common/session/AuthjsSession.ts b/src/common/session/AuthjsSession.ts index 5d3ff360..5b3686ae 100644 --- a/src/common/session/AuthjsSession.ts +++ b/src/common/session/AuthjsSession.ts @@ -1,23 +1,21 @@ -import { NextAuthResult } from "next-auth" +import { Session } from "next-auth" import { UnauthorizedError } from "@/common" import ISession from "./ISession" export default class AuthjsSession implements ISession { - private readonly auth: NextAuthResult + private readonly auth: () => Promise - constructor(config: { auth: NextAuthResult }) { + constructor(config: { auth: () => Promise }) { this.auth = config.auth } async getIsAuthenticated(): Promise { - const { auth } = this.auth - const session = await auth() + const session = await this.auth() return session != null } async getUserId(): Promise { - const { auth } = this.auth - const session = await auth() + const session = await this.auth() if (!session || !session.user || !session.user.id) { throw new UnauthorizedError("User ID is unavailable because the user is not authenticated.") } diff --git a/src/composition.ts b/src/composition.ts index 88c7316c..8faf4981 100644 --- a/src/composition.ts +++ b/src/composition.ts @@ -79,7 +79,7 @@ const oauthTokenRepository = new FallbackOAuthTokenRepository({ const logInHandler = new LogInHandler({ oauthTokenRepository }) -export const auth = NextAuth({ +export const { signIn, auth, handlers: authHandlers } = NextAuth({ adapter: PostgresAdapter(pool), secret: env.getOrThrow("NEXTAUTH_SECRET"), theme: { From ad64c355bc56f9e20ff1b871276fe678bb6f5e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=B8vring?= Date: Tue, 30 Jul 2024 11:23:10 +0200 Subject: [PATCH 02/10] Installs Font Awesome brand icons --- package-lock.json | 12 ++++++++++++ package.json | 1 + 2 files changed, 13 insertions(+) diff --git a/package-lock.json b/package-lock.json index c32293f9..3ec07985 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "@emotion/react": "^11.13.0", "@emotion/styled": "^11.13.0", "@fortawesome/fontawesome-svg-core": "^6.6.0", + "@fortawesome/free-brands-svg-icons": "^6.6.0", "@fortawesome/free-solid-svg-icons": "^6.6.0", "@fortawesome/react-fontawesome": "^0.2.2", "@mui/icons-material": "^5.16.5", @@ -963,6 +964,17 @@ "node": ">=6" } }, + "node_modules/@fortawesome/free-brands-svg-icons": { + "version": "6.6.0", + "resolved": "https://registry.npmjs.org/@fortawesome/free-brands-svg-icons/-/free-brands-svg-icons-6.6.0.tgz", + "integrity": "sha512-1MPD8lMNW/earme4OQi1IFHtmHUwAKgghXlNwWi9GO7QkTfD+IIaYpIai4m2YJEzqfEji3jFHX1DZI5pbY/biQ==", + "dependencies": { + "@fortawesome/fontawesome-common-types": "6.6.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/@fortawesome/free-solid-svg-icons": { "version": "6.6.0", "resolved": "https://registry.npmjs.org/@fortawesome/free-solid-svg-icons/-/free-solid-svg-icons-6.6.0.tgz", diff --git a/package.json b/package.json index bea2a467..24eea081 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "@emotion/react": "^11.13.0", "@emotion/styled": "^11.13.0", "@fortawesome/fontawesome-svg-core": "^6.6.0", + "@fortawesome/free-brands-svg-icons": "^6.6.0", "@fortawesome/free-solid-svg-icons": "^6.6.0", "@fortawesome/react-fontawesome": "^0.2.2", "@mui/icons-material": "^5.16.5", From c51686d47c67067696c0ec8cf18ea691ba94a852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=B8vring?= Date: Tue, 30 Jul 2024 11:23:30 +0200 Subject: [PATCH 03/10] Adds custom sign in page --- src/app/auth/signin/page.tsx | 127 +++++++++++++++++++++++++ src/composition.ts | 3 + src/features/auth/view/SignInTexts.tsx | 89 +++++++++++++++++ 3 files changed, 219 insertions(+) create mode 100644 src/app/auth/signin/page.tsx create mode 100644 src/features/auth/view/SignInTexts.tsx diff --git a/src/app/auth/signin/page.tsx b/src/app/auth/signin/page.tsx new file mode 100644 index 00000000..1bd4cd05 --- /dev/null +++ b/src/app/auth/signin/page.tsx @@ -0,0 +1,127 @@ +import Image from "next/image" +import Link from "next/link" +import { Box, Button, Stack, Typography } from "@mui/material" +import { signIn } from "@/composition" +import { env } from "@/common" +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" +import { faGithub } from "@fortawesome/free-brands-svg-icons" +import SignInTexts from "@/features/auth/view/SignInTexts" + +const SITE_NAME = env.getOrThrow("NEXT_PUBLIC_SHAPE_DOCS_TITLE") +const HELP_URL = env.get("NEXT_PUBLIC_SHAPE_DOCS_HELP_URL") + +export default async function SignInPage() { + return ( + + + + + ) +} + +const InfoColumn = () => { + return ( + + + + ) +} + +const SignInColumn = () => { + const title = `Get started with ${SITE_NAME}` + return ( + + + + + {`${SITE_NAME} + + + {title} + + + {title} + + + + + +