feat: new "safe" procedure without unauth throwing

This commit is contained in:
Christel Westerberg
2024-07-08 14:53:48 +02:00
parent 17bc18ce2b
commit da343f45da
10 changed files with 117 additions and 69 deletions

View File

@@ -10,7 +10,7 @@ import { unauthorizedError } from "./errors/trpc"
typeof auth
type CreateContextOptions = {
auth: () => Promise<Session>
auth: () => Promise<Session | null>
lang: Lang
pathname: string
uid?: string | null
@@ -50,7 +50,7 @@ export function createContext() {
const session = await auth()
const webToken = webviewTokenCookie?.value
if (!session?.token && !webToken) {
throw unauthorizedError()
return null
}
return session || ({ token: { access_token: webToken } } as Session)