add tanstack/react-query

This commit is contained in:
smanylov
2025-12-02 17:11:53 +07:00
parent d89cc35fca
commit 6d47fa7fbb
15 changed files with 209 additions and 94 deletions
+9 -6
View File
@@ -25,9 +25,13 @@ export async function decrypt(session: string | undefined = '') {
}
}
export async function createSession(token: string) {
export async function createSession(token: string, email: string) {
const expiresAt = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);
const session = await encrypt({ token, expiresAt });
const session = await encrypt({
token,
email,
expiresAt
});
const cookieStore = await cookies();
cookieStore.set('session', session, {
@@ -39,7 +43,7 @@ export async function createSession(token: string) {
})
}
export async function getSessionToken(): Promise<string | null> {
export async function getSessionData(type: 'token' | 'email'): Promise<string | null> {
const cookieStore = await cookies();
const sessionCookie = cookieStore.get('session')?.value;
@@ -49,15 +53,14 @@ export async function getSessionToken(): Promise<string | null> {
const payload = await decrypt(sessionCookie);
if (payload && typeof payload === 'object' && 'token' in payload) {
return payload.token as string;
if (payload && typeof payload === 'object' && type in payload) {
return payload[type] as string;
}
return null;
}
export async function deleteSession() {
const cookieStore = await cookies()
cookieStore.delete('session')