add tanstack/react-query
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user