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
- Unknown attribute type: varchar / text
Since the `string` type is deprecated I tried using `varchar` and `text` in some newer tables, but when running `appwrite pull tables && appwrite types ./src/li...
- trying to figure out how to activate my...
please help
- Bug: TOTP MFA verification always fails ...
*Bug: TOTP MFA verify always returns `user_invalid_token` (Cloud 1.8.1, Frankfurt)** Project ID: `68dd48440003e537d849` SDK: `appwrite@18.2.0` (also tested wit...