We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cant sign in
appwrite.ts
"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!); try { const session = (await cookies()).get("appwrite-session"); console.log(session) if (!session || !session.value) { throw new Error("No session"); } client.setSession(session.value); return { get account() { return new Account(client); }, }; } catch(error){ console.error('Error:', JSON.stringify(error, null, 2)); } } 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); } }; }
user.actions.ts
'use server'; import { ID } from "node-appwrite"; import { createAdminClient, createSessionClient } from "../appwrite"; import { cookies } from "next/headers"; import { parseStringify } from "../utils"; export const signIn = async ({ email, password }: signInProps) => { try { const { account } = await createAdminClient(); const response = await account.createEmailPasswordSession(email, password); return parseStringify(response); } catch (error) { console.error('Error', error); } } export const signUp = async (userData: SignUpParams) => { const { email, password, firstName, lastName } = userData; try { const { account } = await createAdminClient(); const newUserAccount = await account.create( ID.unique(), email, password, `${firstName} ${lastName}` ); const session = await account.createEmailPasswordSession(email, password); cookies().set("appwrite-session", session.secret, { path: "/", httpOnly: true, sameSite: "strict", secure: true, }); return parseStringify(newUserAccount); } catch (error) { console.error('Error', error); } } export async function getLoggedInUser() { try { const { account } = await createSessionClient(); const user = await account.get(); return parseStringify(user); } catch (error) { console.log(error) return null; } } export const logoutAccount = async () => { try { const { account } = await createSessionClient(); cookies().delete('appwrite-session'); await account.deleteSession('current'); } catch (error) { return null; } }
In the console, I got the following error Error: Cannot destructure property 'account' of '(intermediate value)' as it is undefined.
I also tried to log the session object
{ "name": "appwrite-session", "value": "" }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Cant sign in
appwrite.ts
user.actions.ts
In the console, I got the following error
Error: Cannot destructure property 'account' of '(intermediate value)' as it is undefined.
I also tried to log the session object
The text was updated successfully, but these errors were encountered: