mirror of
https://gitlab.massbug.com/massbug/judge4c.git
synced 2025-07-04 15:41:17 +00:00
feat(auth): add getCurrent function for authentication
This commit is contained in:
parent
546e431f2a
commit
2572b4dae5
22
src/features/auth/actions.ts
Normal file
22
src/features/auth/actions.ts
Normal 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;
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user