
TypeScript
const { Client, Account } = require('appwrite');
const client = new Client();
client
.setEndpoint('xxxxxxxxxxxxxxxxxxxxx')
.setProject('xxxxxxxxxxxxxxxxx');
const authenticateAndGenerateJWT = async (email, password) => {
try {
const account = new Account(client);
// Step 1: Authenticate the user and create a session
const session = await account.createEmailPasswordSession(email, password);
console.log('Session created successfully:', session);
// Step 2: Set the session token for subsequent requests
client.setSession(session); // Use the session ID as the token
// Step 3: Generate JWT
const jwt = await account.createJWT();
console.log('JWT created successfully:', jwt.jwt);
return jwt.jwt; // Return the generated JWT
} catch (error) {
console.error('Error:', error.message);
throw new Error('Failed to authenticate or create JWT.');
}
};
error
TypeScript
Error: User (role: guests) missing scope (account)
Error: Failed to authenticate or create JWT.
TL;DR
To generate a JWT after authentication, developers should ensure the user has the necessary scope. In this case, the error 'User (role: guests) missing scope (account)' indicates a lack of permissions. Make sure the guest role has the 'account' scope enabled in the Appwrite console.Recommended threads
- "The document data is missing. Try again...
Hello, I am getting this error suddenly. I have been using this service for a year now, and I haven't made any changes to my code since then. My app was workin...
- Error: The document data is missing. Try...
I am not able to create any document on some of the collection/ DBs. As I can see many of us facing the same issue, need a quick resolution from the Appwrite Te...
- Appwrite Error: 401 Unauthorized on getC...
Hi everyone, I'm getting an error while trying to fetch the current user using Appwrite in my React project. Here's the error log: auth.js:41 GET https://fra....
