diff --git a/src/features/auth/actions.ts b/src/features/auth/actions.ts new file mode 100644 index 0000000..74796c3 --- /dev/null +++ b/src/features/auth/actions.ts @@ -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; + } +};