fix: improve auth handling and logging
This commit is contained in:
@@ -50,9 +50,9 @@ export async function request<T>(
|
||||
const nr = Math.random()
|
||||
console.log(`START REQUEST ${nr}`)
|
||||
console.time(`OUTGOING REQUEST ${nr}`)
|
||||
console.log(`Sending reqeust to ${env.CMS_URL}`)
|
||||
console.log(`Query:`, print(query as DocumentNode))
|
||||
console.log(`Variables:`, variables)
|
||||
// console.log(`Sending reqeust to ${env.CMS_URL}`)
|
||||
// console.log(`Query:`, print(query as DocumentNode))
|
||||
// console.log(`Variables:`, variables)
|
||||
|
||||
const response = await client.request<T>({
|
||||
document: query,
|
||||
@@ -64,7 +64,7 @@ export async function request<T>(
|
||||
})
|
||||
|
||||
console.timeEnd(`OUTGOING REQUEST ${nr}`)
|
||||
console.log({ response })
|
||||
// console.log({ response })
|
||||
|
||||
return { data: response }
|
||||
} catch (error) {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { TRPCError } from "@trpc/server"
|
||||
import { redirect } from "next/navigation"
|
||||
|
||||
import { Lang } from "@/constants/languages"
|
||||
import { login } from "@/constants/routes/handleAuth"
|
||||
import { webviews } from "@/constants/routes/webviews"
|
||||
import { appRouter } from "@/server"
|
||||
import { createContext } from "@/server/context"
|
||||
@@ -13,12 +14,11 @@ const createCaller = createCallerFactory(appRouter)
|
||||
export function serverClient() {
|
||||
return createCaller(createContext(), {
|
||||
onError: ({ ctx, error, input, path, type }) => {
|
||||
console.error(`Server Client error for ${type}: ${path}`)
|
||||
console.error(`[serverClient] error for ${type}: ${path}`, error)
|
||||
|
||||
if (input) {
|
||||
console.error(`Received input:`)
|
||||
console.error(input)
|
||||
console.error(`[serverClient] received input:`, input)
|
||||
}
|
||||
console.error(error)
|
||||
|
||||
if (error instanceof TRPCError) {
|
||||
if (error.code === "UNAUTHORIZED") {
|
||||
@@ -41,12 +41,13 @@ export function serverClient() {
|
||||
redirectUrl
|
||||
)
|
||||
|
||||
console.log(`[serverClient] onError redirecting to: ${redirectUrl}`)
|
||||
redirect(redirectUrl)
|
||||
}
|
||||
|
||||
redirect(
|
||||
`/${lang}/login?redirectTo=${encodeURIComponent(`/${lang}/${pathname}`)}`
|
||||
)
|
||||
const redirectUrl = `${login[lang]}?redirectTo=${encodeURIComponent(`/${lang}/${pathname}`)}`
|
||||
console.log(`[serverClient] onError redirecting to: ${redirectUrl}`)
|
||||
redirect(redirectUrl)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user