forked from adrianhajdin/banking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappwrite.ts
44 lines (35 loc) · 1007 Bytes
/
appwrite.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"use server";
import { Client, Account, Databases, Users } from "node-appwrite";
import { cookies } from "next/headers";
export async function createSessionClient() {
const client = new Client()
.setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT!)
.setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT!);
const session = cookies().get("appwrite-session");
if (!session || !session.value) {
throw new Error("No session");
}
client.setSession(session.value);
return {
get account() {
return new Account(client);
},
};
}
export async function createAdminClient() {
const client = new Client()
.setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT!)
.setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT!)
.setKey(process.env.NEXT_APPWRITE_KEY!);
return {
get account() {
return new Account(client);
},
get database() {
return new Databases(client);
},
get user() {
return new Users(client);
}
};
}