I have added a Google OAuth2 login to my reactjs app. It successfully login the user. When the user logs in, I see that their activity is registered in the Users tab of the Auth section. I also see the session.create event for the logged in user in the Activity tab. However, I get the Unauthorized error when I run account.get(). I do not understand how.
db.js:
import { Client, Storage, Account, Databases, ID, Query, Permission, Role, Functions, OAuthProvider } from 'appwrite';
const client = new Client()
.setEndpoint(import.meta.env.VITE_ENDPOINT)
.setProject(import.meta.env.VITE_PROJECT);
export const account = new Account(client);
const functions = new Functions(client);
export default client;
const storage = new Storage(client);
export const databases = new Databases(client);
export const googleOAuthLogin = async () => {
try {
const userAcc = account.createOAuth2Session(
OAuthProvider.Google,
'http://localhost:5173/user/me',
'http://localhost:5173/',
);
console.log('Success:', userAcc);
} catch (error) {
console.error('Error:', error);
}
}
export const getAccount = async () => {
try {
const accnt = await account.get();
console.log('Account gotten successfully:', accnt);
return accnt;
} catch (err) {
console.error('Error:', err);
}
}
Me.jsx:
import React, { useEffect } from 'react';
import { getAccount } from '../db';
const Me = () => {
useEffect(() => {
const testingGetAccount = async () => {
try {
const accnt = await getAccount();
console.log('THIS IS ACCOUNT:', accnt);
} catch (err) {
console.error('Error', err); }
}
testingGetAccount();
}, []);
}
GET https://cloud.appwrite.io/v1/account 401 (Unauthorized)
Error getting account: AppwriteException: User (role: guests) missing scope (account)
Recommended threads
- Flutter OAuth2 does not attach Google se...
Hi Appwrite team, I’m using Appwrite Auth in a Flutter mobile app and trying to upgrade an anonymous user to Google OAuth. Docs say that if there is already a...
- TablesDB `updateRows` returns `database_...
Hi Appwrite team! I’m seeing a strange issue with TablesDB bulk row updates on a self-hosted Appwrite instance. **Environment** - Appwrite self-hosted `1.9.0` ...
- [SOLVED] Realtime Missing Channels
```js useEffect(() => { let subscription: RealtimeSubscription; async function loadChips() { try { const {rows: chi...