-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use httpOnly cookie for authenticated requests
- Loading branch information
1 parent
0323f80
commit cf34c17
Showing
16 changed files
with
88 additions
and
158 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
This file was deleted.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
import { tryGetToken } from "@/lib/token"; | ||
"use client"; | ||
|
||
export const AuthBoundary = async ({ | ||
import { userOptions } from "@/lib/options"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
|
||
export const AuthBoundary = ({ | ||
fallback, | ||
children, | ||
}: Readonly<{ | ||
fallback: React.ReactNode; | ||
children: React.ReactNode; | ||
}>) => { | ||
try { | ||
await tryGetToken(); | ||
return <>{children}</>; | ||
} catch { | ||
return <>{fallback}</>; | ||
} | ||
const { data: user } = useQuery(userOptions()); | ||
|
||
if (user?.id) return children; | ||
|
||
return fallback; | ||
}; |
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,15 @@ | ||
import { getQueryClient } from "@/lib/getQueryClient"; | ||
import { userOptions } from "@/lib/options"; | ||
import { HydrationBoundary, dehydrate } from "@tanstack/react-query"; | ||
import type { PropsWithChildren } from "react"; | ||
|
||
export const PrefetchUserBoundary = async ({ children }: PropsWithChildren) => { | ||
const queryClient = getQueryClient(); | ||
await queryClient.prefetchQuery(userOptions()); | ||
|
||
return ( | ||
<HydrationBoundary state={dehydrate(queryClient)}> | ||
{children} | ||
</HydrationBoundary> | ||
); | ||
}; |
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
Oops, something went wrong.