SolidJSS
SolidJSโ€ข2y agoโ€ข
2 replies
Costinha

Cloud Flare Context is not defined when using Session

Im getting this message every time i try to call a server action that calls useSession hook
Uncaught (in promise) Error: Context is not available


it only happens on CloudFlare preset builds. On preset cloudflare-modules
the error is
SES_UNHANDLED_REJECTION: Error: Context is not available



import { useSession } from 'vinxi/http';

export interface UserSession {
    id: number;
}

function getSession() {
    'use server';
    return useSession<UserSession>({
        password: process.env.SESSION_SECRET!
    });
}

export async function getSessionData() {
    'use server';
    const session = await getSession();
    if (!session.data.id) {
        return null;
    }
    return session.data;
}

export async function login() {
    'use server';
    const session = await getSession();
    await session.update(() => ({
        id: 1
    }));

    return session.data;
}

export async function logout() {
    'use server';
    const session = await getSession();
    await session.clear();
}
image.png
Was this page helpful?