@@ -2,10 +2,11 @@ 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+ // Accept an invitation via token
910export async function GET ( req : NextRequest ) {
1011 const token = req . nextUrl . searchParams . get ( 'token' )
1112
@@ -14,7 +15,7 @@ export async function GET(req: NextRequest) {
1415 return NextResponse . redirect (
1516 new URL (
1617 '/invite/invite-error?reason=missing-token' ,
17- process . env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
18+ env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
1819 )
1920 )
2021 }
@@ -25,10 +26,7 @@ export async function GET(req: NextRequest) {
2526 // No need to encode API URL as callback, just redirect to invite page
2627 // The middleware will handle proper login flow and return to invite page
2728 return NextResponse . redirect (
28- new URL (
29- `/invite/${ token } ?token=${ token } ` ,
30- process . env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
31- )
29+ new URL ( `/invite/${ token } ?token=${ token } ` , env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai' )
3230 )
3331 }
3432
@@ -44,7 +42,7 @@ export async function GET(req: NextRequest) {
4442 return NextResponse . redirect (
4543 new URL (
4644 '/invite/invite-error?reason=invalid-token' ,
47- process . env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
45+ env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
4846 )
4947 )
5048 }
@@ -54,7 +52,7 @@ export async function GET(req: NextRequest) {
5452 return NextResponse . redirect (
5553 new URL (
5654 '/invite/invite-error?reason=expired' ,
57- process . env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
55+ env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
5856 )
5957 )
6058 }
@@ -64,7 +62,7 @@ export async function GET(req: NextRequest) {
6462 return NextResponse . redirect (
6563 new URL (
6664 '/invite/invite-error?reason=already-processed' ,
67- process . env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
65+ env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
6866 )
6967 )
7068 }
@@ -107,7 +105,7 @@ export async function GET(req: NextRequest) {
107105 return NextResponse . redirect (
108106 new URL (
109107 `/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'
108+ env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
111109 )
112110 )
113111 }
@@ -123,7 +121,7 @@ export async function GET(req: NextRequest) {
123121 return NextResponse . redirect (
124122 new URL (
125123 '/invite/invite-error?reason=workspace-not-found' ,
126- process . env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
124+ env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
127125 )
128126 )
129127 }
@@ -151,10 +149,7 @@ export async function GET(req: NextRequest) {
151149 . where ( eq ( workspaceInvitation . id , invitation . id ) )
152150
153151 return NextResponse . redirect (
154- new URL (
155- `/w/${ invitation . workspaceId } ` ,
156- process . env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
157- )
152+ new URL ( `/w/${ invitation . workspaceId } ` , env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai' )
158153 )
159154 }
160155
@@ -179,17 +174,14 @@ export async function GET(req: NextRequest) {
179174
180175 // Redirect to the workspace
181176 return NextResponse . redirect (
182- new URL (
183- `/w/${ invitation . workspaceId } ` ,
184- process . env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
185- )
177+ new URL ( `/w/${ invitation . workspaceId } ` , env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai' )
186178 )
187179 } catch ( error ) {
188180 console . error ( 'Error accepting invitation:' , error )
189181 return NextResponse . redirect (
190182 new URL (
191183 '/invite/invite-error?reason=server-error' ,
192- process . env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
184+ env . NEXT_PUBLIC_APP_URL || 'https://simstudio.ai'
193185 )
194186 )
195187 }
0 commit comments