appwrite icon indicating copy to clipboard operation
appwrite copied to clipboard

🐛 Bug Report: Unable to get current user session on functions using jwt

Open Irutom opened this issue 1 year ago • 15 comments

👟 Reproduction steps

            import { Client} from 'node-appwrite';
            const userClient = new Client();
            const userAccount = new Account(userClient);

            userClient.setEndpoint(FUNCTIONS_END_POINT)
                .setProject(PROJECT_ID)
                .setJWT(x-appwrite-user-jwt);

            const currentSession = await userAccount.getSession('current');

👍 Expected behavior

getSession('current') should return the current user session that is being used.

👎 Actual Behavior

Fails with user_session_not_found error.

{"code":404,"type":"user_session_not_found","response":{"message":"The current user session could not be found."...}},

🎲 Appwrite version

Appwrite Cloud

💻 Operating system

Linux

🧱 Your Environment

1.5.5

👀 Have you spent some time to check if this issue has been raised before?

  • [X] I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

Irutom avatar May 21 '24 23:05 Irutom

@Irutom, thanks for creating this issue! 🙏 I talked with team and we want to make sure the get current session API returns the session matching the session id embedded in the JWT token.

stnguyen90 avatar May 24 '24 18:05 stnguyen90

Hi @stnguyen90 I'm interested in working on this issue. Can I work on it?

nicklm0 avatar Jun 05 '24 02:06 nicklm0

@nickaldwin, assigned! Thanks for your interest! 🙏🏼

stnguyen90 avatar Jun 05 '24 23:06 stnguyen90

@nickaldwin, assigned! Thanks for your interest! 🙏🏼

@stnguyen90 Thank you so much

nicklm0 avatar Jun 06 '24 00:06 nicklm0

Hi @stnguyen90, Good morning and good evening! I hope you're doing great. This is my first time contributing to Appwrite. I'm having trouble replicating the issue on my end. I've followed the setup instructions and tried the reproduction steps, but I'm still facing difficulties.

Could you please provide more details on how to access and use the Appwrite Cloud function to replicate the issue?

nicklm0 avatar Jun 07 '24 09:06 nicklm0

@nickaldwin, have you looked through these docs?

That said, you don't even need to use an Appwrite function for this. You should be able to use a client SDK to

  1. Create an email password session
  2. Create a JWT token

Then, use a server SDK to set the JWT token and call Get session using "current" as the ID

stnguyen90 avatar Jun 07 '24 22:06 stnguyen90

@nickaldwin, have you looked through these docs?

That said, you don't even need to use an Appwrite function for this. You should be able to use a client SDK to

  1. Create an email password session
  2. Create a JWT token

Then, use a server SDK to set the JWT token and call Get session using "current" as the ID

Hi @stnguyen90,

I will follow this. Thank you so much for providing the reference to replicate the issue.

nicklm0 avatar Jun 07 '24 23:06 nicklm0

Hi @stnguyen90,

I hope you're well. I wanted to ask if there is a deadline for this issue. I apologize for not submitting a PR yet; this is my first time working with Appwrite, and I am still familiarizing myself with the codebase. I am very eager to work on this issue and would appreciate it if I could have some extra time to complete it. Thank you for understanding.

nicklm0 avatar Jun 13 '24 14:06 nicklm0

@nickaldwin, the sooner the better. Please keep us updated on your progress. Otherwise, I'll need to unassign you.

stnguyen90 avatar Jun 17 '24 23:06 stnguyen90

Hi @stnguyen90

I will unassign myself from this issue due to upcoming commitments that will require my full attention. I apologize for any inconvenience this may cause and appreciate your understanding. It has been a pleasure contributing to Appwrite, and I look forward to contributing again in the future when my schedule allows.

nicklm0 avatar Jun 18 '24 04:06 nicklm0

Hey @stnguyen90 , I can take this up.!

Souptik2001 avatar Jun 20 '24 03:06 Souptik2001

@Souptik2001, assigned! Thanks for your interest! 🙏🏼

stnguyen90 avatar Jun 20 '24 04:06 stnguyen90

Hi @stnguyen90

I will unassign myself from this issue due to upcoming commitments that will require my full attention. I apologize for any inconvenience this may cause and appreciate your understanding. It has been a pleasure contributing to Appwrite, and I look forward to contributing again in the future when my schedule allows.

No worries at all! Feel free to come back when you find the time 👋🏼

stnguyen90 avatar Jun 20 '24 04:06 stnguyen90

@stnguyen90 i will come back promise

nicklm0 avatar Jun 20 '24 10:06 nicklm0

Hi @stnguyen90 I have raised a PR for this one.

I have attached the detailed approach of the solution in the PR description itself. If you suggest some other approach please let me know. 👍

Souptik2001 avatar Jun 24 '24 09:06 Souptik2001

Hi Guys,

Were you able to solve this?

I am using this for a game that I am creating in unity. In my scenario I am saving the session in my game and hence need to verify it when user opens my game again. Thanks

mandeepdhalor28 avatar Sep 02 '24 11:09 mandeepdhalor28