logto-io / js

🤓 Logto JS SDKs.
https://docs.logto.io/quick-starts/
MIT License
67 stars 40 forks source link

How to access idToken from local storage using VUE SDK? #509

Closed onkarkore closed 1 year ago

onkarkore commented 1 year ago

We are currently doing POC to use logto for managing login. Our application is written in Vue3. I am able to do login and register integration successfully.

An approach that we are following (please correct if anything is missing):

  1. Login or Register the user using logto
  2. use isAutheticated function to manage logged vs non logged in behavior
  3. get id token from local storage and pass it to each API call
  4. Backend interceptor verifies the token, gets user information from logto and pass to the controller

Questions on the approach:

  1. How to get an id token from local storage using SDK? Currently, we are reading from local storage using key logto:<applicationId>:idToken
  2. How to refresh the id token using the refresh token?
charIeszhao commented 1 year ago

You don't have to worry about the two questions you asked. By using the Vue SDK, it automatically cached issued access token in local storage, and read it first from the local storage when you call getAccessToken(). Also, it automatically re-generates a new access token if the cached one is expired.

Therefore, the only thing you need to do is calling the no-brainer function getAccessToken()