Skip to content
Back

Can't create JWT for anonymous account

  • 0
  • Web
OmniPvP
25 Jul, 2024, 12:01
TypeScript
const router = express.Router();

const client = new Client()
  .setEndpoint(process.env.APPWRITE_ENDPOINT!)
  .setProject(process.env.APPWRITE_PROJECT_ID!);

const account = new Account(client);

router.post("/", async (req: Request, res: Response) => {
  try {
    const session = await account.createAnonymousSession();

    const jwt = await account.createJWT();

    res.cookie("token", jwt.jwt, { httpOnly: true });
    res.json({
      message: "Anonymous login successful",
    });
  } catch (error) {
    res.status(500).json({ error: (error as Error).message });
  }
});

"error": "User (role: guests) missing scope (account)"

Any solutions? My end goal is to be able to convert anonymous users to full users and preserve everything while doing so

TL;DR
Developers want to create a JWT for an anonymous account but encounter a 'User (role: guests) missing scope (account)' error. The issue may be related to setting the session secret on the client after a login. Ensure the session secret is retrieved using the server SDK with the key. To fix this, you need to modify the code to include setting the session secret properly.
darShan
25 Jul, 2024, 12:33

afaik, you need to set the session secret on client after a login.

darShan
25 Jul, 2024, 12:34

session secret is only retrieved when using server sdk with key.

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