Hey 😄
I'm not able to create a User und send him a verification mail.
Always receive /v1/account/verification 401 (Unauthorized)
there is no old session, cause i get /v1/account/sessions/current 401 (Unauthorized) too
just using the signIn as documented with account.get() results in
AppwriteException: User (role: guests) missing scope (account)
Can you provide the code you're using?
sure 1 sec
appwrite.ts
import {Client, Databases, Account, Avatars} from 'appwrite';
import {environment} from '@environment/environment';
export const client = new Client();
client
.setEndpoint('<endpoint>') // blanked but set in my Code
.setProject(environment.projectId)
.setLocale('de-DE');
export const account: Account = new Account(client);
export const databases: Databases = new Databases(client);
export const avatars: Avatars = new Avatars(client);
export { ID } from 'appwrite';
auth.service.ts
async signIn(email: string, password: string) {
try {
await account.deleteSession('current');
const session = account.createEmailPasswordSession(email, password);
session.then((response) => {
console.info('Session created', response);
}).catch((error) => {
console.error('Session creation failed', error);
})
const user = await account.get();
if (!user) {
console.error('User not found');
this.toast.error('User not found');
return;
}
} catch (err) {
console.error(err);
throw new Error;
}
}
async signUp(email: string, password: string, username: string) {
try {
const newAccount = await account.create(ID.unique(), email, password, username);
if (!newAccount) {
console.error('Account creation failed');
this.toast.error('Account creation failed');
return;
}
const avatarUrl = avatars.getInitials(username);
await this.signIn(email, password);
// Tried with verification here
// await account.createVerification('https://environment.baseUrl/verify');
const newUser = await databases.createDocument(
this.databaseId,
this.collectionId,
ID.unique(),
{
userId: newAccount.$id,
email,
username,
avatar: avatarUrl
}
);
return newUser;
} catch (err) {
console.error(err);
throw new Error;
}
}
tried the signUp without the signIn, just account.create -> account.createVerification
went through some posts and did alot try and error, now I'm a bit lost
After creating the account you need to create a new session so you will have to do the createEmailPasswordSession. Are you actually getting after account.deleteSession() ?
I can't remember if no current session exists does deleteSession throw and prevent the code from progressing
Removed the line and tried signIn
And?
/v1/account 401 (Unauthorized)
AppwriteException: User (role: guests) missing scope (account)
Does it tell you which method is throwing that?
Do you have a stack trace?
Can you try this?
async signIn(email: string, password: string) {
try {
const session = await account.createEmailPasswordSession(email, password);
const user = await account.get();
if (!user) {
console.error('User not found');
this.toast.error('User not found');
return;
}
} catch (err) {
console.error(err);
throw new Error;
}
}
Recommended threads
- [SOLVED] curl error Number: 6 — function...
Hello, I invested a lot of time in this error in a fresh install of appwrite 1.8.1 and lasted until fix, this if for helping anyone that can have the same weird...
- general_bad_request when creating accoun...
I have created a new bug request, could anyone have a look - https://github.com/appwrite/appwrite/issues/11908?
- Cannot use custom SMTP for messaging (SM...
Hey there! I'm on Appwrite Self-hosted 1.9.0. I've never used the messaging feature before, always sent emails through functions or a custom backend, but I'v...