@@ -9,29 +9,24 @@ export async function GET(req: NextRequest) {
9
9
if ( ! session || ! session . user ?. email ) {
10
10
return new NextResponse ( "Unauthorized" , { status : 401 } ) ;
11
11
}
12
- const userEmail = session . user . email ;
13
- const emailParam = req . nextUrl . searchParams . get ( "email" ) ;
14
-
15
- if ( userEmail !== emailParam ) {
16
- return new NextResponse ( "Forbidden" , { status : 403 } ) ;
17
- }
18
12
19
- const application = await prisma . application . findFirst ( {
13
+ const userEmail = session . user . email ;
14
+ const user = await prisma . user . findUnique ( {
20
15
where : { email : userEmail } ,
21
- select : { approved : true }
16
+ include : { application : true }
22
17
} ) ;
23
- if ( ! application ? .approved ) {
24
- return new NextResponse ( "Application was not approved " , { status : 403 } ) ;
18
+ if ( ! user || ! user . application || ! user . application . approved ) {
19
+ return new NextResponse ( "Forbidden " , { status : 403 } ) ;
25
20
}
26
21
22
+ const email = user . application . email ;
23
+ if ( ! email ) {
24
+ return new NextResponse ( "Missing email" , { status : 400 } ) ;
25
+ }
27
26
const token = process . env . QRCODE_TOKEN ;
28
27
if ( ! token ) {
29
28
return new NextResponse ( "Token not present" , { status : 400 } ) ;
30
29
}
31
- const email = req . nextUrl . searchParams . get ( "email" ) ;
32
- if ( ! email ) {
33
- return new NextResponse ( "Missing email" , { status : 400 } ) ;
34
- }
35
30
const targetUrl = `https://fullyhacksqr.acmcsuf.com/users/${ email } /qr.png` ;
36
31
const imageRes = await fetch ( targetUrl , {
37
32
headers : {
0 commit comments