Back

User (role: guest) missing scope (account) via Appsmith

  • 1
  • Web
Drake
5 Apr, 2023, 08:59

Otherwise, Im curious about the configuration of the get current session and how you're setting the headers

TL;DR
User is experiencing an issue with missing scope (account) via Appsmith. They mention trying to use the SDK offline and it not working. They also inquire about separate APIs for updating user email or name. The user receives a potential solution involving a JS Object. However, they mention that their server cannot run MongoDB and they need to find another workaround. The conversation continues with troubleshooting suggestions and requests for code and network logs. No solution is provided in the thread.
Goose
5 Apr, 2023, 08:59

If I use fetch, how do I get the Fallback-Cookie?

Goose
5 Apr, 2023, 09:01

User (role: guest) missing scope (account) via Appsmith

Goose
5 Apr, 2023, 09:12

I used console.log(...response.headers) to see all the headers but it only returns me with

Drake
5 Apr, 2023, 09:17

This is from the create email session?

Goose
5 Apr, 2023, 09:17

yes it is

Drake
5 Apr, 2023, 09:18

What's the code and what's the network logs?

Goose
5 Apr, 2023, 09:20
Drake
5 Apr, 2023, 09:26

I'm pretty sure you can create async functions so you can use await and avoid the confusing then callbacks.

It looks like the cookies are set properly so no fallback header is returned...does manually calling the account get work? Does using the Appwrite SDK to call account get work?

Drake
5 Apr, 2023, 09:27

For manual account get API call, you might need to include credentials in the options and set it to include like https://github.com/appwrite/sdk-for-web/blob/1dde5c7bc91b18bfc1f4e2a80b0ba77017db66fe/src/client.ts#L370

Goose
5 Apr, 2023, 09:35

Its okay I'll use the callbacks because the function SubmitLogin cannot support async since its connected to a button I tried calling it manually using the API and the SDK still produces the same output

Drake
5 Apr, 2023, 09:40

That's bizarre it doesn't work...it doesn't make sense...I'll have to play around with this myself in the morning

Goose
5 Apr, 2023, 09:40

Okay thankyou for your quick reply

Drake
5 Apr, 2023, 15:39

well..my server can't run mongodb so it can't run appsmith and it doesn't look like i can set a custom hostname on the cloud instance so im going to have to find another workaround

Drake
5 Apr, 2023, 17:32

okay! so it looks like JS Object runs in a service worker and that's why the cookie isn't being returned and stored. another weird thing is localstorage works so if you try to set the header, it will be overwritten by what's in localstorage (null/empty string). soooo this is what i got working...

CreateEmailSession query with body of:

TypeScript
{"email":{{this.params.email}},"password": {{this.params.password}}}

Then, I have a JS Object named authService that has:

TypeScript
export default {
    createEmailSession: async (email, password) => {
        await CreateEmailSession.run({email, password});
        const fallbackCookies = CreateEmailSession.responseMeta.headers['X-Fallback-Cookies'][0];
        if (typeof window !== 'undefined' && window.localStorage) {
            window.localStorage.setItem('cookieFallback', fallbackCookies);
        }
        
        const client = new Appwrite.Client().setEndpoint(constants.endpoint).setProject(constants.project);
        const account = new Appwrite.Account(client);
        const user = await account.get();
        storeValue('user', user);
    },
    deleteSession: async () => {
        const client = new Appwrite.Client().setEndpoint(constants.endpoint).setProject(constants.project);
        const account = new Appwrite.Account(client);
        await account.deleteSession('current');
        removeValue('user')
    }
}
Drake
5 Apr, 2023, 17:36

The result:

Drake
5 Apr, 2023, 17:49

keke this works on Appsmith cloud too

Goose
6 Apr, 2023, 02:11

Amazing stuff Steven!

Goose
6 Apr, 2023, 02:18

Thank you so much! 😀

Goose
6 Apr, 2023, 02:34

Also quick question, I'm reading the docs right now but it seems that updating the user email or name is on seperate APIs? Why is that? why not just put it in one API?

Drake
6 Apr, 2023, 03:02

Update email is a bit more complicated and requires extra authentication

Goose
8 Jun, 2023, 00:26

Hey sorry to bring this ticket up again, but I wanted to ask if I'm using the SDK will it try to connect to an internet? Because when I try it offline it seems like it doesnt work. I have the appwrite self hosted locally and the sdk endpoint pointing to that endpoint

Drake
8 Jun, 2023, 00:28

Nope, it only connects to the endpoint you specify.

Btw, it's best to make a new post in <#1072905050399191082> rather than reusing an old post for a different topic

Goose
8 Jun, 2023, 00:28

sorry about that thankyou for the quick reply

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more