Back

401 Authentication error when all my credentials are correct?

  • 0
  • Databases
  • Auth
  • Web
  • Cloud
lordrhodes.
19 Mar, 2025, 15:36

So I'm working through the ideas tutorial and just to be sure I have copied and pasted all the code over and fixed all errors. Now I'm getting a 401 error I've checked that my endpoint and project ID are correct. Should I try using an API key instead?

Would love any help with this

TL;DR
Developers facing authentication issue with account.get() method, receiving a 401 error despite correct credentials and following tutorial. Solution: The error is expected when user isn't authenticated. Check code for account.get() call.
Kenny
19 Mar, 2025, 15:39

Could you provide your code that is throwing a 401?

lordrhodes.
19 Mar, 2025, 15:48

Certainly, here it is import { Client, Databases, Account } from "appwrite";

const client = new Client(); console.log('this is the client', client);

client.setEndpoint("https://cloud.appwrite.io/v1") .setProject("67d9e1fa00246f29e7c2");

export const account = new Account(client);

console.log('this is the account', account);

export const databases = new Databases(client); console.log('this is the database', databases);

lordrhodes.
19 Mar, 2025, 15:49

This is what I'm getting in my browser console ''XHRGET https://cloud.appwrite.io/v1/account [HTTP/2 401 228ms] ''

Kenny
19 Mar, 2025, 15:49

Can you show me the call you're making to the account? Like maybe account.get()?

lordrhodes.
19 Mar, 2025, 15:49

I've double checked all my creds are correct and I'm following this tutorial so I know my code is correct had to fix a few minor issues:

https://appwrite.io/docs/tutorials/react/step-1

lordrhodes.
19 Mar, 2025, 15:50

Good question, I don't think I can tbh. The code I just provided is doing that under the hood I think

lordrhodes.
19 Mar, 2025, 15:52

So I've followed the tutorial to the letter and I'm still getting this. Do you think it could have something to do with the order in which I grab things. So there is a login page

lordrhodes.
19 Mar, 2025, 15:52

But I'm not logged in yet

lordrhodes.
19 Mar, 2025, 15:52

Maybe it's a silly suggestion

Kenny
19 Mar, 2025, 15:54

Can you give me the exact error from console, with the stack trace. I suspect it comes from the UserProvider init function.

lordrhodes.
19 Mar, 2025, 15:56

Here is the title:

lordrhodes.
19 Mar, 2025, 15:56
Kenny
19 Mar, 2025, 15:56

Yea, so this is expected. If the user isn't authenticated and you do account.get() it throws an error.

lordrhodes.
19 Mar, 2025, 15:57

Here is the header stack trace

lordrhodes.
19 Mar, 2025, 15:57

Oh shoot it's giving me this Your message could not be delivered. This is usually because you don't share a server with the recipient or the recipient is only accepting direct messages from friends. You can see the full list of reasons here: https://support.discord.com/hc/en-us/articles/360060145013

lordrhodes.
19 Mar, 2025, 15:57

I see, is this a good sign

lordrhodes.
19 Mar, 2025, 15:58
TypeScript
    https
host
    cloud.appwrite.io
filename
    /v1/account
Address
    172.67.36.127:443
Status
401```'''
Kenny
19 Mar, 2025, 15:58

Yea, if you see in the code

TypeScript
...
async function init() {
  try {
    const loggedIn = await account.get();
    setUser(loggedIn);
  } catch (err) {
    setUser(null);
  }
}
...

you are catching the error that is thown and setting the user to null

Kenny
19 Mar, 2025, 15:59

Have you impemented logging in? If so once you login do you still get this issue?

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