fix(auth): make things work

This commit is contained in:
Michael Zetterberg
2024-05-20 09:05:49 +02:00
parent c4912bbb94
commit 476e9f7582
19 changed files with 122 additions and 82 deletions

View File

@@ -1,22 +0,0 @@
"use client"
import { useParams } from "next/navigation"
import { useEffect } from "react"
import { login } from "@/constants/routes/handleAuth"
import { SESSION_EXPIRED } from "@/server/errors/trpc"
import type { ErrorPage } from "@/types/next/error"
import type { LangParams } from "@/types/params"
export default function ProtectedError({ error }: ErrorPage) {
const params = useParams<LangParams>()
useEffect(() => {
if (error.message === SESSION_EXPIRED) {
const loginUrl = login[params.lang]
window.location.assign(loginUrl)
}
}, [error.message, params.lang])
return null
}

View File

@@ -1,23 +1,34 @@
"use client" // Error components must be Client Components
import { usePathname } from "next/navigation"
import { useParams, usePathname } from "next/navigation"
import { useEffect } from "react"
import { findLang } from "@/constants/languages"
import { login } from "@/constants/routes/handleAuth"
import { SESSION_EXPIRED } from "@/server/errors/trpc"
import { firaMono, firaSans } from "@/app/[lang]/(live)/fonts"
import styles from "./error.module.css"
import { LangParams } from "@/types/params"
export default function Error({
error,
}: {
error: Error & { digest?: string }
}) {
const params = useParams<LangParams>()
useEffect(() => {
// Log the error to an error reporting service
console.error(error)
}, [error])
if (error.message === SESSION_EXPIRED) {
const loginUrl = login[params.lang]
window.location.assign(loginUrl)
}
}, [error, params.lang])
const pathname = usePathname()
const lang = findLang(pathname)