File tree Expand file tree Collapse file tree
src/app/api/admin/upgrade Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { NextResponse } from "next/server" ;
2+ import { connectDB } from "@/lib/mongodb" ;
3+ import { User } from "@/lib/models" ;
4+ import { cookies } from "next/headers" ;
5+ import { verifySessionToken } from "@/lib/auth" ;
6+
7+ export const dynamic = "force-dynamic" ;
8+
9+ export async function GET ( ) {
10+ try {
11+ const token = cookies ( ) . get ( "rk-auth-session" ) ?. value ;
12+ const session = await verifySessionToken ( token ) ;
13+
14+ if ( ! session ) {
15+ return NextResponse . json ( { error : "You must be logged in first. Go to /login." } ) ;
16+ }
17+
18+ if ( session . email !== "reavanthchowdary4@gmail.com" ) {
19+ return NextResponse . json ( { error : "Only the founder can run this upgrade." } , { status : 403 } ) ;
20+ }
21+
22+ const db = await connectDB ( ) ;
23+ if ( ! db ) return NextResponse . json ( { error : "Database error" } , { status : 500 } ) ;
24+
25+ const user = await User . findByIdAndUpdate ( session . id , { role : "ADMIN" } , { new : true } ) ;
26+
27+ return NextResponse . json ( {
28+ success : true ,
29+ message : "🎉 SUCCESS! Your account has been upgraded to ADMIN." ,
30+ nextSteps : "IMPORTANT: You must log out and log back in right now for the Admin features to unlock." ,
31+ email : user . email ,
32+ role : user . role
33+ } ) ;
34+
35+ } catch ( error : unknown ) {
36+ return NextResponse . json ( { error : "Server Error" , details : String ( error ) } , { status : 500 } ) ;
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments