feat(auth): add getCurrent function for authentication

This commit is contained in:
ngc2207 2025-02-01 10:02:56 +08:00
parent 546e431f2a
commit 2572b4dae5

View File

@ -0,0 +1,22 @@
import { cookies } from "next/headers";
import { AUTH_COOKIE } from "./constants";
import { Account, Client } from "node-appwrite";
export const getCurrent = async () => {
try {
const client = new Client()
.setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT!)
.setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT!);
const session = (await cookies()).get(AUTH_COOKIE);
if (!session) return null;
client.setSession(session.value);
const account = new Account(client);
return await account.get();
} catch {
return null;
}
};