Skip to content
Back

[SOLVED] Can not get the logged in user data in NextJS app

  • 0
  • Web
Zaki
6 Nov, 2025, 11:47

I'm trying to get the user data after i log in with otp but it get this error :

AppwriteException: User (role: guests) missing scopes (["account"]) at Generator.next (<anonymous>) { code: 401, type: 'general_unauthorized_scope', response: '{"message":"User (role: guests) missing scopes (["account"])","code":401,"type":"general_unauthorized_scope","version":"1.8.0"}' } Failed to get authenticated user

the error comes from the getAuthunticatedUser function, I also attached 3 images shows my two server actions and the sdk setup repo for full code: https://github.com/MohamedZakidev/store-it

TL;DR
Developers initially had trouble accessing logged-in user data in a NextJS app, believing they were using the wrong SDK version. The issue was resolved by importing the correct component from 'node-appwrite'. It was clarified that the dev key is different from the API key, which might be causing the problem. It was recommended to ensure the API key is properly set, especially when working with SSR. Suggestions were given regarding possible causes of the issue when obtaining the session secret. The support thread also referenced an authentication tutorial for NextJS. Finally, an error regarding the user's scope was highlighted, leading to the conclusion that the specific role and scopes
Guille
6 Nov, 2025, 12:01

did you follow this tutorial for authentication with SSR? https://appwrite.io/docs/tutorials/nextjs-ssr-auth/step-1

Zaki
6 Nov, 2025, 12:13

yes actually my code was exactly like the docs but the problem is i donot get a session secret to put as a value in the cookie but one of the lead engineers in appwrite told me that i donot have to setup the cookie it will be set automatically but i still have the same issue

Zaki
6 Nov, 2025, 12:14

btw iam using otp and not sure this is the reason i donot get a session secret

Zaki
6 Nov, 2025, 15:10

@Guille

Guille
6 Nov, 2025, 17:49

I haven't used it with OTP, when you said you don't get the secret, it's after create the session? Are you using cloud or self-hosting?

Steven
6 Nov, 2025, 17:58

Who/where/what were you told?

Steven
6 Nov, 2025, 17:59

You're probably not getting the secret because you're not setting an API key

Zaki
6 Nov, 2025, 18:19

Iam using a dev api key

Zaki
6 Nov, 2025, 18:29
Steven
6 Nov, 2025, 20:20

Ya, you're doing SSR, so you need to do these SSR things

Steven
6 Nov, 2025, 20:20

Btw, best to not create duplicate support threads.

Steven
6 Nov, 2025, 20:21

Dev key is not API key

Zaki
6 Nov, 2025, 20:21

I thought it is the same but for development

Zaki
6 Nov, 2025, 20:22
Zaki
6 Nov, 2025, 20:23

I can not find the setkey method i only get setDevKey

Steven
6 Nov, 2025, 20:25

Maybe you're not using the node SDK

Zaki
6 Nov, 2025, 20:26

So i should import from node/appwrite not appwrite

Zaki
6 Nov, 2025, 20:27

Thx i wil try these changes

Guille
7 Nov, 2025, 18:59

Yes you need to import from (you need to add it to your project previously)

TypeScript
import { Client } from 'node-appwrite'
Zaki
7 Nov, 2025, 23:19

thx it works now

Steven
10 Nov, 2025, 17:22

[SOLVED] Can not get the logged in user data in NextJS app

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more