@@ -2,10 +2,13 @@ import { NextRequest, NextResponse } from 'next/server'
22import { randomUUID } from 'crypto'
33import { and , eq } from 'drizzle-orm'
44import { getSession } from '@/lib/auth'
5+ import { env } from '@/lib/env'
56import { db } from '@/db'
67import { user , workspace , workspaceInvitation , workspaceMember } from '@/db/schema'
78
8- // GET /api/workspaces/invitations/accept - Accept an invitation via token
9+ export const dynamic = 'force-dynamic'
10+
11+ // Accept an invitation via token
912export async function GET ( req : NextRequest ) {
1013 const token = req . nextUrl . searchParams . get ( 'token' )
1114
@@ -14,7 +17,7 @@ export async function GET(req: NextRequest) {
1417 return NextResponse . redirect (
1518 new URL (
1619 '/invite/invite-error?reason=missing-token' ,
17- process . env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
20+ env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
1821 )
1922 )
2023 }
@@ -25,10 +28,7 @@ export async function GET(req: NextRequest) {
2528 // No need to encode API URL as callback, just redirect to invite page
2629 // The middleware will handle proper login flow and return to invite page
2730 return NextResponse . redirect (
28- new URL (
29- `/invite/${ token } ?token=${ token } ` ,
30- process . env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
31- )
31+ new URL ( `/invite/${ token } ?token=${ token } ` , env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai' )
3232 )
3333 }
3434
@@ -44,7 +44,7 @@ export async function GET(req: NextRequest) {
4444 return NextResponse . redirect (
4545 new URL (
4646 '/invite/invite-error?reason=invalid-token' ,
47- process . env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
47+ env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
4848 )
4949 )
5050 }
@@ -54,7 +54,7 @@ export async function GET(req: NextRequest) {
5454 return NextResponse . redirect (
5555 new URL (
5656 '/invite/invite-error?reason=expired' ,
57- process . env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
57+ env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
5858 )
5959 )
6060 }
@@ -64,7 +64,7 @@ export async function GET(req: NextRequest) {
6464 return NextResponse . redirect (
6565 new URL (
6666 '/invite/invite-error?reason=already-processed' ,
67- process . env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
67+ env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
6868 )
6969 )
7070 }
@@ -107,7 +107,7 @@ export async function GET(req: NextRequest) {
107107 return NextResponse . redirect (
108108 new URL (
109109 `/invite/invite-error?reason=email-mismatch&details=${ encodeURIComponent ( `Invitation was sent to ${ invitation . email } , but you're logged in as ${ userData ?. email || session . user . email } ` ) } ` ,
110- process . env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
110+ env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
111111 )
112112 )
113113 }
@@ -123,7 +123,7 @@ export async function GET(req: NextRequest) {
123123 return NextResponse . redirect (
124124 new URL (
125125 '/invite/invite-error?reason=workspace-not-found' ,
126- process . env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
126+ env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
127127 )
128128 )
129129 }
@@ -151,10 +151,7 @@ export async function GET(req: NextRequest) {
151151 . where ( eq ( workspaceInvitation . id , invitation . id ) )
152152
153153 return NextResponse . redirect (
154- new URL (
155- `/w/${ invitation . workspaceId } ` ,
156- process . env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
157- )
154+ new URL ( `/w/${ invitation . workspaceId } ` , env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai' )
158155 )
159156 }
160157
@@ -179,17 +176,14 @@ export async function GET(req: NextRequest) {
179176
180177 // Redirect to the workspace
181178 return NextResponse . redirect (
182- new URL (
183- `/w/${ invitation . workspaceId } ` ,
184- process . env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
185- )
179+ new URL ( `/w/${ invitation . workspaceId } ` , env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai' )
186180 )
187181 } catch ( error ) {
188182 console . error ( 'Error accepting invitation:' , error )
189183 return NextResponse . redirect (
190184 new URL (
191185 '/invite/invite-error?reason=server-error' ,
192- process . env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
186+ env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
193187 )
194188 )
195189 }
0 commit comments