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
- React-Native cross platform usage
I am about to start making a React-Native app for Web Android and IOS. Testing out the "write anywhere" claim. When setting up my project for the web depoyment...
- How do I reset my self-hosted password w...
It says I need to set up an Simple Mail Transfer Protocol server to reset my password. Is there a different way? Can I manually reset the password from the con...
- Password reset without using the appwrit...
Hi together, i want to change the users password my way. Is there a way to do this? The changePassword requires the oldPassword which is unknown in case of pass...