-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0ff9c1
commit beb50dd
Showing
18 changed files
with
1,184 additions
and
957 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import { adminAuth as auth } from '@/lib/firebaseAdmin'; | ||
|
||
export async function POST(req: NextRequest) { | ||
const { idToken } = await req.json(); | ||
|
||
try { | ||
const expiresIn = 60 * 60 * 24 * 5 * 1000; // 5 days | ||
const sessionCookie = await auth.createSessionCookie(idToken, { expiresIn }); | ||
|
||
const response = NextResponse.json({ status: 'success' }); | ||
response.cookies.set('session', sessionCookie, { | ||
maxAge: expiresIn, | ||
httpOnly: true, | ||
secure: process.env.NODE_ENV === 'production', | ||
path: '/' | ||
}); | ||
|
||
return response; | ||
} catch (error) { | ||
console.error('Error creating session:', error); | ||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import { adminAuth as auth } from '@/lib/firebaseAdmin'; | ||
|
||
export async function GET(req: NextRequest) { | ||
const sessionCookie = req.cookies.get('session')?.value || ''; | ||
|
||
try { | ||
const decodedClaims = await auth.verifySessionCookie(sessionCookie, true); | ||
return NextResponse.json({ authenticated: true, user: decodedClaims }); | ||
} catch (error) { | ||
return NextResponse.json({ authenticated: false }, { status: 401 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.