yuvraj
i'm refactoring my code, but I'm getting this issue when trying to get the current user logged in. My api key is correct with all auth/database scopes. Here are my codes:
Appwrite service
TypeScript
class AppwriteService {
private static adminClient: Client;
private static getAdminClient(): Client {
if (!this.adminClient) {
this.adminClient = new Client()
.setEndpoint(APPWRITE_ENDPOINT)
.setProject(APPWRITE_PROJECT)
.setKey(APPWRITE_API_KEY);
}
return this.adminClient;
}
public static getAppwriteAdminClient() {
const client = this.getAdminClient();
return {
get account() {
return new Account(client);
},
get users() {
return new Users(client);
},
get databases() {
return new Databases(client);
},
};
}
}
export default AppwriteService;
Auth service
TypeScript
class AuthService {
private static readonly account: Account = AppwriteService.getAppwriteAdminClient().account;
public static async getLoggedInUser(): Promise<Models.User<Models.Preferences>> {
return await this.account.get();
}
}
export default AuthService;
usage in page.tsx
TypeScript
const isLoggedIn = await AuthService.getLoggedInUser()
TL;DR
Developers are missing the account scope when trying to get the current logged-in user. In the `AuthService` class, make sure to add the missing scope to the account service call.
Solution:
```javascript
public static async getLoggedInUser(): Promise<Models.User<Models.Preferences>> {
return await this.account.get();
}
``` Recommended threads
- self-hosted auth: /v1/account 404 on saf...
Project created in React/Next.js, Appwrite version 1.6.0. Authentication works in all browsers except Safari (ios), where an attempt to connect to {endpoint}/v1...
- My account is blocked so please check an...
My account is blocked so please unblock my account because all the apps are closed due to which it is causing a lot of problems
- Applying free credits on Github Student ...
So this post is kind of related to my old post where i was charged 15usd by mistake. This happens when you are trying to apply free credits you got from somewh...