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
- Anyone manage to get a slack-bot working...
I'm trying to setup a bot the send and retrieve slack messages to a chat in my site. I've failed with SSE and appwrite functions soo far... i'll trying polling ...
- Fine grained permissions for webRTC hand...
Hi, I am building a WebRTC P2P app for a university project and have hit a security limitation regarding permissions for anonymous users. The Architecture: We ...
- [Sites] Deployment finished but site is ...
The deployment finished and is active but the site shows timeout error.