Skip to content
Back

[Solved] Window not defined | Edge runtime not supported

  • 1
  • Web
D5
14 Nov, 2023, 22:57

Okay, from what I'm seeing it uses client side SDK but passes cookies to server side to avoid conflict so a part is executed client sided as I was supposing

TL;DR
Title: [Solved] Window not defined | Edge runtime not supported; Solution: Use Rest API instead of client SDK for edge runtime.
fafa
14 Nov, 2023, 22:58

The thing is, I don't mind using only Rest API, but the docs are kind of minimal and I have no clue how to properly implement the auth using just rest api. I understand fetching and everything, but what data do I store? do i store it as localstorage like the client sdk? and what does the key/value need to be? What if I want to create a JWT?

It says just this

TypeScript
POST /v1/account/jwt HTTP/1.1
Host: HOSTNAME
Content-Type: application/json
X-Appwrite-Response-Format: 1.4.0
X-Appwrite-Project: 5df5acd0d48c2

But how does the rest api know who the user is? I feel like there's chunks missing

Drake
14 Nov, 2023, 22:59
fafa
14 Nov, 2023, 23:00

That actually helps a lot, thanks Steven! One more question about JWT actually, why is there a legacy sometimes popping up in the cookies using the client sdk?

fafa
14 Nov, 2023, 23:00

a_session_projectid_legacy for example

fafa
14 Nov, 2023, 23:03

It's not consistent, it's very random on logging-in, as I think the client sdk uses localstorage instead of cookies, so it makes even less sense

Drake
14 Nov, 2023, 23:03

The only difference is the samesite option. The legacy one doesn't specify anything for that for backwards compatiblity or something

fafa
14 Nov, 2023, 23:03

Ah, alright

fafa
14 Nov, 2023, 23:04

TL;DR, You should use Rest API if you use edge runtime

fafa
15 Nov, 2023, 07:17

Hey @Steven, Do I need both cookies? Or is just the a_session_projectid enough?

fafa
15 Nov, 2023, 07:28

The thing I don't understand, is if you got for example a cookie called a_session_projectid with the value eyJpZCI6IjY1NTI1ZW...TE3MjBiMTdjOSJ9, and I try to fetch /v1/account with that value using rest api fetched via client, it just says 401

fafa
15 Nov, 2023, 07:30

As far as I understood it, you only need to create a JWT if you want the server to fetch for example, right?

fafa
15 Nov, 2023, 08:19

nvm, seems I got it working!

Thanks everyone for helping with this topic! Setting it as solved.

fafa
15 Nov, 2023, 08:19

[Solved] Window not defined | Edge runtime not supported

Drake
15 Nov, 2023, 13:31

Yes that one should be enough

DragonOP
24 Nov, 2023, 02:08

Hey how were you able to resolve the problem?

fafa
24 Nov, 2023, 05:26

Hey. Are you using nextjs?

DragonOP
24 Nov, 2023, 17:06

Yes

fafa
24 Nov, 2023, 17:09

use rest api instead of client sdk

DragonOP
24 Nov, 2023, 17:12

Can you give me kind of pseudo overview on how to use this

DragonOP
24 Nov, 2023, 17:12

With the rest apiece

fafa
24 Nov, 2023, 17:13

See reference on docs

DragonOP
24 Nov, 2023, 17:14

I simply send jwt tokens along the request and authenticate that?

fafa
24 Nov, 2023, 17:16

You set the token as a cookie with secure and httponly, you use the "Cookie" header as authentication

DragonOP
24 Nov, 2023, 17:17

Thanks

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