
Hi!
This is probably an edge case for Appwrite but is it possible to use the Web SDK getSession without cookie functionality?
The application is currently a NodeJS Console App, using the Server SDK is not feasible as accounts are created externally and API Keys is not an option.
Creating a Session via the email session function works just fine (it obviously doesn't save a cookie)
let credentails = process.env.LOGIN_CREDENTIALS.split(":");
console.log(color.yellow("** Authenticating with master server using provided credentials **"));
session = await account.createEmailSession(
credentails[0],
credentails[1]
);
console.log(color.yellow(`** Logged in as ${session.providerUid}`));
Now onto the part I am getting stuck on:
I noticed there is an getSession(sessionId: string)
function
in the Account
class, unfortunately it crashes Appwrite as it cannot read the cookie for obvious reasons.
appwriteexception: User (role: guests) missing scope (account) at Client.<anonymous> (/workspace/**/node_modules/appwrite/dist/cjs/sdk.js:393:27) at Generator.next (<anonymous>) at fulfilled (/workspace/**/node_modules/appwrite/dist/cjs/sdk.js:24:58) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { code: 401, type: 'general_unauthorized_scope', response: { message: 'User (role: guests) missing scope (account)', code: 401, type: 'general_unauthorized_scope', version: '1.3.1' }}
My question is: Is it possible to:
1st, verify a session by session id without a cookie 2nd, get user details by session id without a cookie
I know that using the Web SDK is not the proper way, but I haven't found a way to authenticate without exposing an api key to users, as it is a public image.

you can get the session by sessionId using getSession(sessionId: string)

I don't understand why it would try to read cookie

it only reads the cookie when you pass "current" as the session

thats what I've tried, according to SO it tries to read a cookie (though I cannot confirm via the source code).
I get message: 'User (role: guests) missing scope (account)',
when using the session.$id variable

alternatively if that's a bug you can try sending an http request without the sdk https://appwrite.io/docs/client/account?sdk=rest-default#accountGetSession

you will require a JWT though

yeah JWT is an issue right now, as I cannot generate one without an active session cookie :/

ah that's why the error

JWT wouldnt be a big deal if I could retrieve session details by ID, that way I can store the SID in a file locally

https://github.com/appwrite/sdk-for-web/blob/7b37a2bec1dbe47b55e2c962996046f56b763192/src/client.ts#L373-L375 I guess I gotta emulate/polyfill local storage

Alright so this issue has been solved in a hacky way:
I've polyfilled the localStorage using node-localstorage and the following 3 lines:
global.window = {
console: {warn: (() => {})},
localStorage: new localstorage.LocalStorage(process.env.STORAGE_PATH ?? "../sessions")
};
Recommended threads
- I create storage and save images in that...
- rate limit for the current endpoint exce...
My site is working fine but sometimes it goes into error like failing to create jwt and rate limit! It breaks the authentication completely! Any quick solution?...
- Google auth
Hi, Guys can you hel me verifing a problem with the database, im creating a auth with google but when i created my user with google auth, no appear my user in ...
