Skip to content
Back

trying to get account using jwt

  • 0
  • Auth
  • Web
root
26 Aug, 2025, 23:03

server side script

TypeScript
async function verifyJWT(token) {
  if (!token) throw new Error("No JWT token provided");
  try {
    const res = await axios.get(`${ENDPOINT}/account`, {
      headers: {
        "X-Appwrite-Project": PROJECT_ID,
        "Authorization": `Bearer ${token}`,
      },
    });
    return res.data;
  } catch (err) {
    console.error("Failed to fetch account data:", err.response?.data || err.message);
    throw new Error("Invalid JWT or unable to fetch account");
  }
}
TypeScript
Failed to fetch account data: {
  message: 'User (role: guests) missing scope (account)',
  code: 401,
  type: 'general_unauthorized_scope',
  version: '1.8.0'
}
Socket auth failed: Invalid JWT or unable to fetch account

~ client side is logged in ~ method of getting jwt below

TypeScript
const jwtResponse = await account.createJWT();
TL;DR
Developers are trying to get an account using a JWT but are facing a 401 error related to missing scope 'account'. The issue lies with the user role not having the necessary scope. The solution would be to update the user's role to include the 'account' scope.
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