magic-js icon indicating copy to clipboard operation
magic-js copied to clipboard

How to keep a user logged in after browser reload?

Open iamwilhelm opened this issue 3 years ago • 1 comments

✅ Prerequisites

  • [✅] Did you perform a cursory search of open issues? Is this question already asked elsewhere?
  • [✅] Are you reporting to the correct repository (magic-sdk)?

❓ Question

I'm able to successfully call loginWithMagicLink, click the email, then call loginWithCredentials to log the user in. When calling isLoggedIn(), it returns true. However if I reload the browser and call loginWithCredentials, it reports and error, saying the Authorization header is missing. And isLoggedIn() returns false.

Is this supposed to happen? I'm guessing no, as the docs talk about keeping the user logged in for 15 mins by default.

Am I supposed to store something to pass into loginWithCredentials? Or am I missing something else, so that when I reload, I can keep the user logged in?

Where are the credentials stored? Is it a browser permission that I need to relax?

🌎 Environment

Software Version(s)
magic-sdk 8.1.1
Browser Firefox 99.0.1
yarn yarn 1.22.18
Operating System macOS 11

iamwilhelm avatar Jun 01 '22 18:06 iamwilhelm

Hello @iamwilhelm, if you are passing in a redirectURI argument to loginWithMagicLink, upon successful auth, loginWithCredential will be called (without arguments) in the redirect context to strip the magic_credential (did token) from window.location.search.

With all that in mind, after successful auth, subsequent loginWithCredential calls do not need to be made. That should be isolated to the redirect context only, and the user shouldn't be given access to call that again.

Could I ask what your use case is or what you're trying to accomplish by calling loginWithCredential again?

ayv8er avatar Aug 01 '22 17:08 ayv8er