
So I am using Nextjs v15 as a full stack and im not sure what the proper flow is
I am trying to compare with supabase where i make a server client and a client client
the 1-1 equivalent i assume is node sdk (server) and web sdk (client)
i use server actions to signup / login / create session with the node sdk client
this works, i can see my user in the appwrite dashboard AND can retrieve the session
but when i am trying to get the client in my react context that I created I am presented with the following errors
GET https://cloud.appwrite.io/v1/account 401 (Unauthorized)
AppwriteException: User (role: guests) missing scope (account)
am i doing something wrong or am i unable to retrieve a session created by the server sdk with the web sdk?

// client.ts
'use client'
import { Client, Account } from 'appwrite'
const NEXT_PUBLIC_APPWRITE_ENDPOINT = String(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT)
const NEXT_PUBLIC_APPWRITE_PROJECT = String(process.env.NEXT_PUBLIC_APPWRITE_PROJECT)
const client = new Client()
.setEndpoint(NEXT_PUBLIC_APPWRITE_ENDPOINT)
.setProject(NEXT_PUBLIC_APPWRITE_PROJECT)
const account = new Account(client)
export { account }
// user-provider.tsx
useEffect(() => {
;(async function run() {
try {
const loggedInUser = await account.get()
setUser(loggedInUser)
} catch (err) {
setUser(null)
}
})()
}, [])

// server.ts
'use server'
import { Client, Account } from 'node-appwrite'
import { cookies } from 'next/headers'
const NEXT_PUBLIC_APPWRITE_ENDPOINT = String(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT)
const NEXT_PUBLIC_APPWRITE_PROJECT = String(process.env.NEXT_PUBLIC_APPWRITE_PROJECT)
const NEXT_APPWRITE_KEY = String(process.env.NEXT_APPWRITE_KEY)
export async function createSessionClient() {
const client = new Client()
.setEndpoint(NEXT_PUBLIC_APPWRITE_ENDPOINT)
.setProject(NEXT_PUBLIC_APPWRITE_PROJECT)
const session = (await cookies()).get('my-custom-session')
if (!session || !session.value) {
throw new Error('No session')
}
client.setSession(session.value)
return {
get account() {
return new Account(client)
},
}
}
export async function createAdminClient() {
const client = new Client()
.setEndpoint(NEXT_PUBLIC_APPWRITE_ENDPOINT)
.setProject(NEXT_PUBLIC_APPWRITE_PROJECT)
.setKey(NEXT_APPWRITE_KEY)
return {
get account() {
return new Account(client)
},
}
}
/signin.action.ts
'use server'
import { createAdminClient } from '@/utils/appwrite/server'
import { cookies } from 'next/headers'
import { redirect } from 'next/navigation'
export async function signinAction(formData: FormData) {
const values = Object.fromEntries(formData.entries())
const email = `${values.email}`
const password = `${values.password}`
const { account } = await createAdminClient()
const session = await account.createEmailPasswordSession(email, password)
;(await cookies()).set('my-custom-session', session.secret, {
path: '/',
httpOnly: true,
sameSite: 'strict',
secure: true,
})
redirect('/')
}
Recommended threads
- Queries Length Error.
Hi All, I am having a issues across my app with how i am getting data, and just wanted to check if this was an issues with the new changes on appwrite over the...
- The current user is not authorized to pe...
I'm just getting this error while it was working couple minutes ago, my users have permissions to access and create tables data but on some databases I'm just g...
- My projects archived. Did not see the up...
Kindly restore project for me: 67680a26001bdf36beb8 You can delete: 678c96ba00305f78bb13 675d05040004853fb43f
