```ts export const createSession = async (user: any, databaseConfig: KVNamespace) => { let absol

export const createSession = async (user: any, databaseConfig: KVNamespace) => {
    let absoluteExpiration = 30 * 24 * 60 * 60;
    let expiration = new TimeSpan(10, 'd');
    const sid = generateRandomString(60, alphabet('a-z', '0-9'));

    const SessionBody = {
        email: user.email,
        email_verified: user.email_verified,
        expires_at: expiration,
    };
    try {
        await databaseConfig.put(sid, user.id, { metadata: SessionBody, expirationTtl: absoluteExpiration });
    } catch (error) {
        throw new Error('Error creating session');
    }

    return sid;
};

Why does value appear as "undefined" in the kv? Also, when I try to get with metadata, it returns null for it.
image.png
Was this page helpful?