
Hey :peepoShy: I receive "AppwriteException: User (role: guests) missing scope (account)" & "<appwriteUrl>/v1/account 401 (Unauthorized)" after Discord redirect. The Email & Password login works as intended.

appwrite.service.ts
@Injectable({
providedIn: 'root'
})
export class AppwriteService {
private readonly client: Client;
public account: Account;
public databases: Databases;
public avatars: Avatars;
constructor() {
this.client = new Client()
.setEndpoint(environment.appwriteUrl)
.setProject(environment.projectId)
.setLocale('de-DE');
this.account = new Account(this.client);
this.databases = new Databases(this.client);
this.avatars = new Avatars(this.client);
}
}
auth.service.ts
@Injectable({
providedIn: 'root',
})
export class AuthService {
private databaseId = environment.databases['users'].databaseId;
private collectionId = environment.databases['users'].collections['userData'].collectionId;
public user = signal<Models.User<any> | null>(null); // Signal for the current User
public isLoggedIn = signal<boolean>(false); // Signal for login status
constructor(
private toast: ToastService,
private router: Router,
private appwrite: AppwriteService,
private logger: NGXLogger
) {
// Currently disabled for testing
// Normaly restores the Session but as this is not working I'm calling this from callback
// will be re enabled when session is working again with oAuth
// checkLogin()
}
/** Check for Session and Login */
public async checkLogin(): Promise<void> {
try {
this.logger.info('Trying to get User');
const userData = await this.appwrite.account.get();
this.logger.info('Trying to get Session');
const session = await this.appwrite.account.getSession('current');
// User is logged in
this.user.set(userData);
this.isLoggedIn.set(true);
this.logger.info('User found successfully');
} catch (error) {
this.logger.error('No User found:');
this.logger.error(error);
this.user.set(null);
this.isLoggedIn.set(false);
}
}
/** Start OAuth2-Session with Discord */
async loginWithDiscord(): Promise<void> {
// Remove current session
try {
await this.appwrite.account.deleteSession('current');
} catch (err) {
console.error('Session deletion failed');
}
this.logger.info('Logging in with Discord');
await this.appwrite.account.createOAuth2Session(
OAuthProvider.Discord,
environment.baseUrl + '/callback',
environment.baseUrl + '/error',
['identify', 'email']
)
}
/** Sign Out the User */
async logout(): Promise<void> {
this.logger.info('Logging out');
try {
await this.appwrite.account.deleteSession('current');
this.user.set(null);
this.isLoggedIn.set(false);
this.logger.info('Logged out successfully');
} catch (error) {
this.logger.error('Logout failed:', error);
this.user.set(null);
this.isLoggedIn.set(false);
}
}
}
callback.component.ts
@Component({
selector: 'app-callback',
imports: [],
templateUrl: './callback.component.html',
styleUrl: './callback.component.scss'
})
export class CallbackComponent {
constructor(
private authService: AuthService,
private appwrite: AppwriteService,
private router: Router,
private logger: NGXLogger
) {
this.logger.warn(this.router.url);
this.logger.warn(window.location.href);
this.handleCallback();
}
private async handleCallback() {
this.logger.info('Got callback from OAuth provider');
this.authService.checkLogin();
}
}

Error from /account
{
"message": "User (role: guests) missing scope (account)",
"code": 401,
"type": "general_unauthorized_scope",
"version": "1.6.0"
}

You have SSR?

No

It's probably a 3rd party cookie problem.
For local development, maybe you can change your browser settings to enable 3rd party cookies.
In production, you'll need to use custom domains

I get something stored in the cookies but its
a_session_projectId_legacy

And 3rd Party Cookies are enabled

There should be a a_session_projectId
one too

you can try inspecting the browser network logs to see if the cookie is there or if there any errors

I only get the legacy cookie

inspect the browser network logs
Recommended threads
- setup custom domain to appwrite but stil...
i just installed a Appwrite instance in my vps and i did all default otions exept the domain i have setuop its dns as A records pointing to my vps ip altho...
- 1.7.x Style issue in the migration page
I am not able to select what to migrate because of the styling... the checkboxes are not showing on any of the appwrite versions 1.7.x. I tried other browsers, ...
- Website not responding on User session T...
The website is not responding after opening the user sessions tab. (The Chrome tab crashes and i need to open a new one )
