Back

[SOLVED] Error 401 (unauthorized) on using get Account

  • 0
  • Accounts
  • Web
Suiii
20 Nov, 2023, 07:26

you need to createsession, check the auth docs

TL;DR
User experienced the error 401 (unauthorized) when using the 'get Account' function. They initially tried to fix it by contacting the appwrite team but had no success. They ended up switching to using Supabase for authentication. Another user also reported experiencing the same problem. Eventually, the user realized that the issue was with their own code and not the appwrite configuration. The error was occurring because they were trying to get the current user without creating a session first. The solution was to use the `account.get()` function after creating a session. The error was resolved, and the user thanked everyone for their help.
Utkarsh Nagar | Utkarshn10
20 Nov, 2023, 07:58

Hey @Ayush yes you need to create a session and then only you will be able to get the details of the logged in account.

Utkarsh Nagar | Utkarshn10
20 Nov, 2023, 08:00

also account.get returns a promise. You will also need to handle that

https://appwrite.io/docs/references/cloud/client-web/account#get%20account

ideclon
20 Nov, 2023, 08:13

Ayush is using await inside an async function

Ayush
20 Nov, 2023, 08:33

Is there anything wrong about it?

D5
20 Nov, 2023, 08:33

Use : account.get();

D5
20 Nov, 2023, 08:34

@Ayush the error seems to be because there's not any active session

D5
20 Nov, 2023, 08:35

Are you sure you have logged in previously?

Ayush
20 Nov, 2023, 08:45

Yess guys I think it's fixed now

Ayush
20 Nov, 2023, 08:45

Thank you everyone for your help

D5
20 Nov, 2023, 09:02

What was the solution?

Ayush
20 Nov, 2023, 09:04

As everyone said, I was trying get the current user without creating any session

Ayush
20 Nov, 2023, 09:04

It was under a useEffect thus it was throwing the error as soon as I reload the page

Ayush
20 Nov, 2023, 09:05

Basically the problem was with my code and not with appwrite configuration

ideclon
20 Nov, 2023, 09:34

No, I was pointing out why you don’t need to deal with the Promise

Ayush
20 Nov, 2023, 09:37

Okay okay got it

Utkarsh Nagar | Utkarshn10
20 Nov, 2023, 09:50

Great!

Ayush
20 Nov, 2023, 09:58

[fixed] Error 401 (unauthorized) on using get Account

Ayush
20 Nov, 2023, 09:58

[SOLVED] Error 401 (unauthorized) on using get Account

Anas Siddiqui
20 Nov, 2023, 18:22

@Ayush Hello bro dm me i want to ask some questions.

Murali
25 Dec, 2023, 18:10

@Ayush I am also getting same problem, I also fetching current user data in useEffect hook, without login also its trying to fetch data. please help me to resolve this issue

Ayush
25 Dec, 2023, 20:04

Hi Murali! I tried fixing it and talking with the appwrite team but couldn't get any useful, So I used supabase instead for the auth functionality

Murali
26 Dec, 2023, 03:59

@Ayush in my case, before logging in, the useEffect hook fetching getCurrentUser, initially there is no session. Don't know how to avoid this

Drake
26 Dec, 2023, 07:10

please create a new <#1072905050399191082> post instead of posting in an old thread

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