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

set_session not working #324

Closed
sangonzal opened this issue Mar 29, 2023 · 7 comments
Closed

set_session not working #324

sangonzal opened this issue Mar 29, 2023 · 7 comments

Comments

@sangonzal
Copy link

Describe the bug

My understanding is that set_session should take in a jwt, and set the session on the supabase client, but when I call set_session with a valid access token, and then right after call get_session, I get back None.

To Reproduce


url = "http://localhost:54321"
key = ""
jwt = ""

supabase: Client = create_client(url, key)

def custom_decode_jwt_payload(token: str):
    _, payload, _ = token.split(".")
    payload += "=" * (-len(payload) % 4)
    payload = base64.urlsafe_b64decode(payload)
    return json.loads(payload)

supabase.auth._decode_jwt = custom_decode_jwt_payload

session = supabase.auth.set_session(jwt, "")
supabase.auth.set_session

print("session: ", supabase.auth.get_session())

Sidenote: I'm currently using thecustom_decode_jwt_payload as a workaround for supabase/supabase-py#395.

Expected behavior
Return the new session, and the supabase client can access protected resources.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Mac
@sangonzal sangonzal changed the title setSession not working set_session not working Mar 29, 2023
@vcscsvcscs
Copy link

vcscsvcscs commented May 23, 2023

same, also it makes it unable to authenticate on lot of functions
Is this lib abadonware in the opensource community?

@bitnom
Copy link

bitnom commented Sep 13, 2023

Just realizing I can't do this. dying

@J0 J0 transferred this issue from supabase/supabase-py Sep 16, 2023
@silentworks
Copy link
Contributor

I'm not fully understanding the reproduction steps, can you please provide an example repo with this issue for me to take a look at?

@fquellec
Copy link

fquellec commented Nov 28, 2023

You need to provide the refresh token of the session to set the session. (I don't know why the refresh token is needed but it works)

session = supabase.auth.set_session(jwt, refresh_token)

@silentworks
Copy link
Contributor

Closing this out as there has been no activity on this issue from OP over a month now.

@canrobins13
Copy link

Tracing through the code because I hit this as well. I was able to work around this by setting persist_session = False in the client options.
This is because set_session calls _save_session, which looks like this:

    def _save_session(self, session: Session) -> None:
        if not self._persist_session:
            self._in_memory_session = session
        ...

I think this should be a one-line fix to remove the conditional, will give it a shot

@canrobins13
Copy link

PR here: #610

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants