Back

check if user is logged in

  • 0
  • Users
  • Accounts
  • Web
Ajit Singh
2 Feb, 2024, 06:31

I have a secondary server where I do some work can i check in that server that the request to that server is sent by a logged in Appwrite user

TL;DR
Developers are discussing how to check if a user is logged in. They suggest using a JWT token and generating a new one on each request. The auth check can be done on the client side, and the server will only receive the request if the user is authenticated. To retrieve the user, the users API can be used on the server. One developer asks if the original request is coming from a client side SDK, and another developer asks if the Django backend is used for anything else. The Django backend is used for running GPU servers on AWS. They are looking for a way to check if the request to a long running endpoint is sent
Steven
2 Feb, 2024, 06:32

You could send the user's JWT token to your server

Ajit Singh
2 Feb, 2024, 06:33

that expires in 15 min should I send a new JWT with each request

Ajit Singh
2 Feb, 2024, 06:34

users sessions can last long

Ajit Singh
2 Feb, 2024, 06:34

What is the recommended whay to work around it

Steven
2 Feb, 2024, 06:40

What's your stack? Can you provide some more detail on your setup?

Ajit Singh
2 Feb, 2024, 06:44

yeah I have an endpoint which makes videos and run some long running processes . I want to put it on my server so that I can use a GPU it is a Python Django backend I have everything else integrated in appwrite how can I check that the request to this long running endpoint is snt by appwrite user.

Ajit Singh
2 Feb, 2024, 06:45

I user Python Django for ruuning the GPU servers on AWS.

Steven
2 Feb, 2024, 06:46

Do you use your Django backend for anything else?

Ajit Singh
2 Feb, 2024, 06:47

No

Dennis Ivy
2 Feb, 2024, 06:49

Is the original request coming from a client side SDK?

Ajit Singh
2 Feb, 2024, 06:50

yes

Dennis Ivy
2 Feb, 2024, 06:52

In that case, you can just run a quick check from the client side and only send that request if the user is authenticated so the server wouldn't get this request from unauthenticated users. Then to retrieve the user, you can just use the users API on the server and get the user by ID:

TypeScript
users.get('[USER_ID]');
Dennis Ivy
2 Feb, 2024, 06:53

Basically, the auth check happens on the client. So you can take advantage of the long lasting session.

Dennis Ivy
2 Feb, 2024, 06:54

Steven's suggestion of a JWT would also should work. Just generate a JWT on each request and send it to verify auth status. The short lived token shouldn't be an issue.

Dennis Ivy
2 Feb, 2024, 06:55

I would just use the JWT

Ajit Singh
2 Feb, 2024, 06:57

Generating a new JWT on each request is not a problem right

because checking if the user is authenticated from client and only sending the request I will have to keep my server endpoint unauthenticated which I can't do because using GPU so it can be expensive

Dennis Ivy
2 Feb, 2024, 06:59

How often will you be making these request?

Ajit Singh
2 Feb, 2024, 06:59

at max 2-3 time/15 min

Dennis Ivy
2 Feb, 2024, 06:59

Just curious if its every couple of seconds or maybe only a few times a day per day

Dennis Ivy
2 Feb, 2024, 06:59

Per user?

Ajit Singh
2 Feb, 2024, 07:00

yeah

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