Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Bug Report: appwrite cli logout automatically #110

Closed
2 tasks done
StarZeus opened this issue Oct 26, 2023 · 17 comments · Fixed by appwrite/sdk-generator#802
Closed
2 tasks done

🐛 Bug Report: appwrite cli logout automatically #110

StarZeus opened this issue Oct 26, 2023 · 17 comments · Fixed by appwrite/sdk-generator#802
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@StarZeus
Copy link

👟 Reproduction steps

  1. Login to appwrite instance from appwrite-cli with appwrite login command and console user id and password
  2. Retrieve project details with `appwrite projects get --projectId
  3. Able to retrieve project details
  4. Retrieve project details with `appwrite projects get --projectId
  5. Getting error message saying "Error User (role: guests) missing scope (projects.read)"

Regardless of what command we execute 2nd time onwards the command fails as the user is not logged in anymore

👍 Expected behavior

appwrite cli should stay logged in until logout

👎 Actual Behavior

appwrite cli logout automatically after each command

🎲 Appwrite version

Version 1.4.x

💻 Operating system

Linux

🧱 Your Environment

Appwrite version 1.4.7 installed on kubernetes v1.20
[email protected] installed on mac os Monterey

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

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

@StarZeus StarZeus added the bug Something isn't working label Oct 26, 2023
@stnguyen90 stnguyen90 self-assigned this Oct 27, 2023
@stnguyen90
Copy link
Contributor

@StarZeus, thanks for creating this issue! 🙏🏼 I just tried this and I can get my project for both attempts.

Would you please check and make sure:

  1. your ~/.appwrite/prefs.json file is not malformed
  2. your ./appwrite.json file is not malformed
  3. you have a CLI session in the Appwrite console at /console/account/sessions

@StarZeus
Copy link
Author

@stnguyen90 - Thank you for looking into this.

To add clarity.

  1. ~/.appwrite/prefs.json is not malformed
  2. ./appwrite.json is not malformed
  3. I can see email session created and see from /console/account/sessions page

Also, I noticed that the ~/.appwrite/pref.json updated with cookies a_session_console_legacy and domain after login but removed immediately after executing 1st command. I believe that's why the 2nd command onwards is not working.

@StarZeus
Copy link
Author

The appwrite url is https and I have set selfSigned=true if that make a difference

@stnguyen90
Copy link
Contributor

Also, I noticed that the ~/.appwrite/pref.json updated with cookies a_session_console_legacy and domain after login but removed immediately after executing 1st command.

It's replaced with an empty string? The only time that would happen is either:

  1. the response header included set-cookie
  2. the config is reset

Maybe you have something between the CLI and Appwrite messing up the cookies?

@stnguyen90
Copy link
Contributor

Does this happen with other commands like appwrite projects list? Do you get logged out from the Appwrite web console?

@StarZeus
Copy link
Author

StarZeus commented Nov 2, 2023

It happens for all command. I'm not logged out from appwrite web console. Thats stays logged in.

After every command the a_session_console_legacy and domain are not in cookie anymore.

"cookie": "route=b1c61a93f68b5c389187caa649ee5027; Expires=Mon, 30-Oct-23 17:02:35 GMT; Max-Age=172800; Path=/(.*); Secure; HttpOnly"

@stnguyen90
Copy link
Contributor

Very bizarre...Would you be able to curl Appwrite to see the full request? Something like:

ENDPOINT="https://[YOUR_HOSTNAME]/v1"

# Sign in (make sure to replace [YOUR_EMAIL] and [YOUR_PASSWORD]
curl -s -k -v -b console-cookies.txt -c console-cookies.txt "$ENDPOINT/account/sessions/email" \
  -H 'content-type: application/json' \
  -H 'x-appwrite-project: console' \
  --data-raw '{"email":"[YOUR_EMAIL]","password":"[YOUR_PASSWORD]"}' \
  --compressed \
  --insecure

# List projects
curl -s -k -v -b console-cookies.txt -c console-cookies.txt "$ENDPOINT/projects" \
  -H 'content-type: application/json' \
  -H 'x-appwrite-project: console' \
  --compressed \
  --insecure

@stnguyen90
Copy link
Contributor

@StarZeus, have you had a chance to try the commands I suggested. Btw, I'll need to close this soon due to inactivity.

@StarZeus
Copy link
Author

I'll try the above curl command and post an update

@StarZeus
Copy link
Author

StarZeus commented Jan 3, 2024

@stnguyen90 - I was able to execute above curl commands. I can see project details returning even when I hit the 2nd curl repeatedly.

@stnguyen90
Copy link
Contributor

"cookie": "route=b1c61a93f68b5c389187caa649ee5027; Expires=Mon, 30-Oct-23 17:02:35 GMT; Max-Age=172800; Path=/(.*); Secure; HttpOnly"

What is this you shared? This doesn't look like what Appwrite would typically respond. It seems there's something else that is passing back additional cookies...And since the CLI only grabs the first set-cookie, the cookie gets overwritten

@StarZeus
Copy link
Author

StarZeus commented Jan 4, 2024

I am running appwrite in kubernetes cluster. "route" is the Sticky/Affinity cookie set by the nginx ingress controller so that subsequent requests are sent to the same container.

Is there a reason why the cli captures only the first cookie?

@StarZeus
Copy link
Author

StarZeus commented Jan 6, 2024

Below change to capture all cookies from response fixes my problem. I'll be raising a PR

    let cookieString = "";
    response.headers["set-cookie"].forEach((cookie) => {
        cookieString += cookie.split(";")[0] + ";";
    });        
    globalConfig.setCookie(cookieString);

@StarZeus
Copy link
Author

StarZeus commented Jan 6, 2024

Raised PR #104

@StarZeus
Copy link
Author

@stnguyen90 raised StarZeus/sdk-generator#1

@stnguyen90
Copy link
Contributor

@StarZeus, thanks for creating this PR. Would you please create the PR to target our repo instead of your forked master branch?

@StarZeus
Copy link
Author

@stnguyen90 - I have raised a new PR targeting appwrite repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants