-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: add session checker * fix: path
- Loading branch information
Showing
6 changed files
with
62 additions
and
10 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,28 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import { | ||
ApiResponse, | ||
errorResponse, | ||
handleApiResponse, | ||
} from '@/app/util/response'; | ||
import { auth } from '@/auth'; | ||
import { isAuthenticated } from '@/lib/utils'; | ||
|
||
export async function GET( | ||
request: NextRequest, | ||
): Promise<NextResponse<ApiResponse>> { | ||
const session = await auth(); | ||
if (!isAuthenticated(session)) { | ||
return errorResponse( | ||
'You need to be authenticated to access this endpoint', | ||
401, | ||
); | ||
} | ||
const res = await fetch(`${process.env.API_URL}/v1/auth/validate`, { | ||
headers: { | ||
Authorization: `Bearer ${session!.token}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
|
||
return handleApiResponse(res); | ||
} |
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,18 @@ | ||
'use client'; | ||
|
||
import { useEffect } from 'react'; | ||
import { signOut } from 'next-auth/react'; | ||
|
||
export default function SessionChecker() { | ||
useEffect(() => { | ||
fetch(`/api/auth/validate`) | ||
.then(async (res) => { | ||
if (!res.ok && res.status === 401) { | ||
await signOut({ redirect: false }); | ||
} | ||
}) | ||
.catch(() => signOut({ redirect: false })); | ||
}); | ||
|
||
return null; | ||
} |
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
File renamed without changes.
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