21 lines
572 B
JavaScript
21 lines
572 B
JavaScript
import pb from "@/lib/pocketbase"
|
|
import { redirect } from "next/navigation"
|
|
|
|
export const getUserFromCookie = async cookies => {
|
|
const cookie = cookies.get("pb_auth")
|
|
if (!cookie) {
|
|
redirect("/")
|
|
//throw new Error("No authenticated user");
|
|
} else {
|
|
pb.authStore.loadFromCookie(cookie?.value || "")
|
|
return pb.authStore.model
|
|
}
|
|
}
|
|
|
|
export const isAuthenticated = async cookieStore => {
|
|
const cookie = cookieStore.get("pb_auth")
|
|
if (!cookie) return false
|
|
pb.authStore.loadFromCookie(cookie?.value || "")
|
|
return pb.authStore.isValid || false
|
|
}
|