Skip to content

Commit 13cf268

Browse files
committed
Auth flows: update sign-in links to /auth/signin/user; allow org signup via signup_intent cookie; unknown emails redirect to signup error; prevent /restricted redirects on /auth/*; org sign-in routes through signup start
1 parent edfedf3 commit 13cf268

7 files changed

Lines changed: 30 additions & 11 deletions

File tree

app/auth/signin/SignInClient.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export default function SignInClient() {
99
const [loading, setLoading] = React.useState(false)
1010

1111
const cb = params.get("callbackUrl") || "/"
12-
const from = params.get("from") || undefined
1312
const mode = params.get("mode") || undefined
1413

1514
return (
@@ -46,9 +45,6 @@ export default function SignInClient() {
4645
</span>
4746
{loading ? "Redirecting…" : "Continue with Google"}
4847
</button>
49-
{from && (
50-
<p className="mt-2 text-[11px] text-muted-foreground">After sign-in you’ll be returned to: {from}</p>
51-
)}
5248
<p className="mt-4 text-[11px] text-muted-foreground">
5349
By continuing, you agree to our Terms and acknowledge our Privacy Policy.
5450
</p>

app/auth/signin/organization/page.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function Page() {
1212
<Link href="/auth/signup/organization">Sign up</Link>
1313
</Button>
1414
<Button asChild variant="default">
15-
<Link href="/auth/signin">Sign in</Link>
15+
<Link href="/auth/signin/user">Sign in</Link>
1616
</Button>
1717
</header>
1818

@@ -24,7 +24,16 @@ export default function Page() {
2424
<p className="text-sm text-foreground/70">Continue with Google</p>
2525
</CardHeader>
2626
<CardContent>
27-
<Button className="w-full" onClick={() => signIn("google", { callbackUrl: "/org/dashboard" })}>
27+
<Button
28+
className="w-full"
29+
onClick={() => {
30+
try {
31+
// Allow account creation when starting from org sign-in
32+
document.cookie = "signup_intent=1; Max-Age=600; Path=/; SameSite=Lax";
33+
} catch {}
34+
return signIn("google", { callbackUrl: "/auth/signup/organization/start" });
35+
}}
36+
>
2837
Continue with Google
2938
</Button>
3039
<p className="mt-3 text-xs text-center text-foreground/60">

app/auth/signup/organization/page.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default function Page() {
3333
<Link href="/auth/signup/organization">Sign up</Link>
3434
</Button>
3535
<Button asChild variant="default">
36-
<Link href="/auth/signin">Sign in</Link>
36+
<Link href="/auth/signin/user">Sign in</Link>
3737
</Button>
3838
</header>
3939

@@ -52,7 +52,13 @@ export default function Page() {
5252
type="button"
5353
variant="outline"
5454
className="w-full flex items-center justify-center gap-2 bg-orange-500 hover:bg-orange-600 text-white hover:text-white focus:text-white active:text-white border-transparent"
55-
onClick={() => signIn("google", { callbackUrl: "/auth/signup/organization/start" })}
55+
onClick={() => {
56+
try {
57+
// Allow unknown emails during signup flow only
58+
document.cookie = "signup_intent=1; Max-Age=600; Path=/; SameSite=Lax"
59+
} catch {}
60+
return signIn("google", { callbackUrl: "/auth/signup/organization/start" })
61+
}}
5662
>
5763
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="18" height="18" aria-hidden="true" className="text-white">
5864
<path fill="currentColor" d="M43.611,20.083H42V20H24v8h11.303c-1.649,4.657-6.08,8-11.303,8c-6.627,0-12-5.373-12-12 s5.373-12,12-12c3.059,0,5.842,1.154,7.961,3.039l5.657-5.657C33.691,6.053,29.082,4,24,4C12.955,4,4,12.955,4,24 s8.955,20,20,20s20-8.955,20-20C44,22.659,43.862,21.35,43.611,20.083z"/>

app/auth/signup/user/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default function Page() {
5050
<main className="min-h-[calc(100vh-4rem)] p-6 bg-gradient-to-b from-primary/20 via-transparent to-transparent">
5151
<header className="mb-6 flex justify-end gap-2">
5252
<Button asChild variant="outline">
53-
<Link href="/auth/signin">Sign in</Link>
53+
<Link href="/auth/signin/user">Sign in</Link>
5454
</Button>
5555
<Button asChild variant="default">
5656
<Link href="/auth/signup/user">Sign up</Link>

app/auth/signup/user/school/cwru/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default function Page() {
1313
<Link href="/auth/signup/user">Sign up</Link>
1414
</Button>
1515
<Button asChild variant="default">
16-
<Link href="/auth/signin">Sign in</Link>
16+
<Link href="/auth/signin/user">Sign in</Link>
1717
</Button>
1818
</div>
1919
</header>

lib/auth.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Adapter } from "next-auth/adapters";
33
import { PrismaAdapter } from "@auth/prisma-adapter";
44
import GoogleProvider from "next-auth/providers/google";
55
import { prisma } from "@/lib/prisma";
6+
import { cookies } from "next/headers";
67
import type { Session } from "next-auth";
78
import type { JWT } from "next-auth/jwt";
89

@@ -32,7 +33,13 @@ export const authOptions: NextAuthOptions = {
3233
if (email) {
3334
const existing = await prisma.user.findUnique({ where: { email } })
3435
if (!existing) {
35-
// Abort sign-in and redirect to signup with error message
36+
// If user came from signup, allow account creation
37+
const c = await cookies()
38+
const allowSignup = c.get("signup_intent")?.value === "1"
39+
if (allowSignup) {
40+
return true
41+
}
42+
// Otherwise send back to signup with a clear error
3643
return "/auth/signup/organization?error=no_account"
3744
}
3845
// Best-effort: sync Google avatar for existing users lacking image

middleware.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export async function middleware(req: NextRequest) {
9191
if (
9292
isAuthed &&
9393
!onOrgPaths &&
94+
!onAuthPages &&
9495
role === "VOLUNTEER" &&
9596
typeof token?.email === "string" &&
9697
!token.email.toLowerCase().endsWith("@case.edu") &&

0 commit comments

Comments
 (0)