Hi all, I'm following the repo https://github.com/adrianhajdin/aora to make the app work in browser with react-native-web
. The sign-in feature works well on mobile devices, but not in web browsers.
In https://github.com/adrianhajdin/aora/blob/main/app/(auth)/sign-in.jsx, after clinking Sign In
button with correct credentials, I got an error ```GET https://cloud.appwrite.io/v1/account 401 (Unauthorized)
AppwriteException: User (role: guests) missing scope (account)
at Client.<anonymous> (http://localhost:8081/node_modules/expo-router/entry.bundle?platform=web&dev=true&hot=false&lazy=true&transform.routerRoot=app&resolver.environment=client&transform.environment=client:93245:19)
at Generator.next (<anonymous>)
at fulfilled (http://localhost:8081/node_modules/expo-router/entry.bundle?platform=web&dev=true&hot=false&lazy=true&transform.routerRoot=app&resolver.environment=client&transform.environment=client:92875:26)```
I've tried to add some debug code around the signIn
call in sign-in.jsx
:
const session = await signIn(form.email, form.password);
console.log(`User signed in: ${form.email}`);
console.log(`Session: ${JSON.stringify(session)}`);
const result = await getCurrentUser();```
and also in the `getAccount` method in https://github.com/adrianhajdin/aora/blob/main/lib/appwrite.js :``` console.log("Getting current account");
const currentAccount = await account.get();
console.log(`Current account: ${JSON.stringify(currentAccount)}`);```
I'll paste the whole console output I got from the browser below, since Discord says "Message is too long".
Any help/advice would be greatly appreciated.
entry.bundle?platfor…onment=client:30573 props.pointerEvents is deprecated. Use style.pointerEvents
entry.bundle?platfor…onment=client:93249 Appwrite is using localStorage for session management. Increase your security by adding a custom domain as your API endpoint.
entry.bundle?platfor…onment=client:17566 User signed in: ******@*****.com
entry.bundle?platfor…onment=client:17567 Session: {"$id":"66d7f502c71f38ad8662","$createdAt":"2024-09-04T05:49:54.820+00:00","$updatedAt":"2024-09-04T05:49:54.820+00:00","userId":"66d6631300029d264ea3","expire":"2025-09-04T05:49:54.815+00:00","provider":"email","providerUid":"*******@*****.com","providerAccessToken":"","providerAccessTokenExpiry":"","providerRefreshToken":"","ip":"192.168.65.1","osCode":"MAC","osName":"Mac","osVersion":"10.15","clientType":"browser","clientCode":"CH","clientName":"Chrome","clientVersion":"128.0","clientEngine":"Blink","clientEngineVersion":"128.0.0.0","deviceName":"desktop","deviceBrand":"Apple","deviceModel":"","countryCode":"--","countryName":"Unknown","current":true,"factors":["password"],"secret":"","mfaUpdatedAt":""}
entry.bundle?platfor…onment=client:21499 Getting current account
entry.bundle?platfor…onment=client:93236
GET https://cloud.appwrite.io/v1/account 401 (Unauthorized)
entry.bundle?platfor…onment=client:21511 AppwriteException: User (role: guests) missing scope (account)
at Client.<anonymous> (http://localhost:8081/node_modules/expo-router/entry.bundle?platform=web&de…Root=app&resolver.environment=client&transform.environment=client:93245:19)
at Generator.next (<anonymous>)
at fulfilled (http://localhost:8081/node_modules/expo-router/entry.bundle?platform=web&de…Root=app&resolver.environment=client&transform.environment=client:92875:26)```
do you have add platform "localhost" as web app in your appwrite instance?
But i don't know if it's a good behaviour for a public appwrite instance to add "localhost"
I thought "as long as it works, I don't care whether it's a good behaviour"😂 . I've even tried to put a wildcard * for both iOS and web platform, but the error persists.
Actually I don't have the web platform at first; I created it only because I was hoping it could fix the error. As I'm using Appwrite React Native SDK
, I don't think it really matters whether I have a web app platform in my appwrite instance.
localhost
is automatically allowed - there’s no need to set a Platform for it
How are you accessing the account
object?
I'm accessing the account
object by creating an instance of the Account
class from the react-native-appwrite
library. This instance is initialized with the client
object, which is configured with the Appwrite endpoint, project ID, and platform.
Here is my step-by-step process:
- Importing the
Account
class:
import { Account } from "react-native-appwrite";
- Creating and configuring the client object:
const client = new Client();
client
.setEndpoint(config.endpoint)
.setProject(config.projectId)
.setPlatform(config.platform);
- Creating an instance of the Account class:
const account = new Account(client);
- Using the account object to call methods:
- Creating a user:
const newAccount = await account.create(ID.unique(), email, password, username);
- Signing in a user:
const session = await account.createEmailPasswordSession(email, password);
- Getting the current user:
const currentAccount = await account.get();
Currently the account
object works fine for users signup and signin on both mobile and web platforms, and it could get the correct session
after verifying credentials. However, the account.get()
would get an error after that.
Recommended threads
- Need Help with Google OAuth2 in Expo usi...
I'm learning React Native with Expo and trying to set up Google OAuth2 with Appwrite. I couldn't find any good docs or tutorials for this and my own attempt did...
- Different appwrite IDs are getting expos...
File_URL_FORMAT= https://cloud.appwrite.io/v1/storage/buckets/[BUCKET_ID]/files/[FILE_ID]/preview?project=[PROJECT_ID] I'm trying to access files in my web app...
- Invalid document structure: missing requ...
I just pick up my code that's working a week ago, and now I got this error: ``` code: 400, type: 'document_invalid_structure', response: { message: 'Inv...