-
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(JAQPOT-214): session-checker and refresh-token (#41)
* fix(JAQPOT-214/): session-checker and refresh-token * fix: do not risk the refresh token impl and add todo
- Loading branch information
Showing
11 changed files
with
1,200 additions
and
569 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import { | ||
ApiResponse, | ||
errorResponse, | ||
handleApiResponse, | ||
} from '@/app/util/response'; | ||
import { auth } from '@/auth'; | ||
import { isAuthenticated } from '@/app/util/auth'; | ||
import { generatePaginationAndSortingSearchParams } from '@/app/util/sort'; | ||
|
||
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
3 changes: 1 addition & 2 deletions
3
...d/models/[modelId]/components/TimeAgo.tsx → ...ls/[modelId]/components/JaqpotTimeAgo.tsx
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 |
---|---|---|
@@ -1,8 +1,7 @@ | ||
'use client'; | ||
|
||
import { formatDistance } from 'date-fns'; | ||
import { getUserFriendlyDate } from '@/app/util/date'; | ||
|
||
export default function JaqpotTimeAgo({ date }: { date: Date }) { | ||
return <div>{getUserFriendlyDate(date)}</div>; | ||
return <div title={date.toLocaleString()}>{getUserFriendlyDate(date)}</div>; | ||
} |
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
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