fix: route to /w after signup, remove deprecated getSessionCookie function

This commit is contained in:
Waleed Latif
2025-03-14 16:16:25 -07:00
parent 4deef0b769
commit 42822482fd
3 changed files with 13 additions and 11 deletions
-6
View File
@@ -1,6 +0,0 @@
{
"name": "sim",
"lockfileVersion": 3,
"requires": true,
"packages": {}
}
+2 -2
View File
@@ -65,7 +65,7 @@ export default function SignupPage() {
async function signUpWithGithub() {
try {
await client.signIn.social({ provider: 'github' })
await client.signIn.social({ provider: 'github', callbackURL: '/w' })
} catch (err: any) {
let errorMessage = 'Failed to sign up with GitHub'
@@ -85,7 +85,7 @@ export default function SignupPage() {
async function signUpWithGoogle() {
try {
await client.signIn.social({ provider: 'google' })
await client.signIn.social({ provider: 'google', callbackURL: '/w' })
} catch (err: any) {
let errorMessage = 'Failed to sign up with Google'
+11 -3
View File
@@ -1,5 +1,4 @@
import { NextRequest, NextResponse } from 'next/server'
import { getSessionCookie } from 'better-auth'
export async function middleware(request: NextRequest) {
// Check if the path is exactly /w
@@ -12,8 +11,17 @@ export async function middleware(request: NextRequest) {
return NextResponse.next()
}
// Existing auth check for protected routes
const sessionCookie = getSessionCookie(request)
const cookieHeader = request.headers.get("cookie");
const cookies = cookieHeader?.split("; ").reduce((acc, cookie) => {
const [key, value] = cookie.split("=");
acc.set(key, value);
return acc;
}, new Map());
const sessionCookie =
cookies?.get("better-auth.session_token") ||
cookies?.get("__Secure-better-auth.session_token");
if (!sessionCookie) {
return NextResponse.redirect(new URL('/login', request.url))
}