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

UPDATE THE SESSION FROM THE CLIENT SIDE #6952

Closed
Danztee opened this issue Mar 15, 2023 · 6 comments
Closed

UPDATE THE SESSION FROM THE CLIENT SIDE #6952

Danztee opened this issue Mar 15, 2023 · 6 comments
Labels
enhancement New feature or request triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@Danztee
Copy link

Danztee commented Mar 15, 2023

Description 📓

I am working on a project, in the settings page i can update the name, username e.t.c after updating, it updates in the database but the session won't change until i log out and log in back then the new data from the database will now be updated. we need a way to update the session from the client when updates like this happen. the database is sending me the updated data after successful update. so we need a way to pass the updated data to the session from the client so that we did not need to log out and login again for the changes to be made

How to reproduce ☕️

no one for now

Contributing 🙌🏽

Yes, I am willing to help implement this feature in a PR

@Danztee Danztee added enhancement New feature or request triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Mar 15, 2023
@magicspon
Copy link

it's a bit of hack, but this seems to do the job:

function useReloadSession() {
  const reloadSession = () => {
    const event = new Event('visibilitychange')
    document.dispatchEvent(event)
  }

  return reloadSession
}

then once you've updated your user data:

const reloadSession = useReloadSession()

... 
onSuccess = () => reloadSession()

@Danztee
Copy link
Author

Danztee commented Mar 15, 2023

it's a bit of hack, but this seems to do the job:

function useReloadSession() {
  const reloadSession = () => {
    const event = new Event('visibilitychange')
    document.dispatchEvent(event)
  }

  return reloadSession
}

then once you've updated your user data:

const reloadSession = useReloadSession()

... 
onSuccess = () => reloadSession()

where will i put all these code? which file?

@magicspon
Copy link

ignore the code...

after you update your username/name/whatever

call this:

const event = new Event('visibilitychange')
document.dispatchEvent(event)

@Danztee
Copy link
Author

Danztee commented Mar 15, 2023

my problem is dat how can i pass the newly updated user data to the session. if i log out and log in back, it gets the newly updated data from d backend that is normal but how can i pass the new data to the session without logging out and logging in...

that code u provided just reload the session not update d session


THIS IS MY ISSUE
i updated my username in d frontend and it has been updated in the DB and the API sent a response with the newly updated data. so i want to pass the new updated data to the session. of course, if i log out and log in, it'll get the new data. but how can i pass the new data to the session without logging out and logging in after updating in the frontend

@magicspon
Copy link

this is where i got the code snippet from:
#596 (comment)

@balazsorban44
Copy link
Member

See the related discussion here: #3941 Might have some good pointers.

Unfortunately, the discussion got flooded by unrelated comments and I stopped iterating on the feature, but we could revisit and add something in the future.

It would be nice to have a built-in solution, but updating the session makes little sense for JWT sessions for example, so we might need to think about the right API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

3 participants