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

Question: Is there any way to know if a user is still logged in? #4

Open
jvolker opened this issue Oct 15, 2019 · 2 comments
Open

Question: Is there any way to know if a user is still logged in? #4

jvolker opened this issue Oct 15, 2019 · 2 comments

Comments

@jvolker
Copy link
Collaborator

jvolker commented Oct 15, 2019

How long is a token valid?
Is there any way to know if a user is still logged (since it is stored internally) in or if the token expired?

I would like to play around with the web clipper and am wondering how often I would have to login again and how to check if it's still valid.

Thanks.

@jmwohl
Copy link
Member

jmwohl commented Nov 5, 2019

Two weeks. Loopback, the framework the API is built with, doesn't use JWTs, it has its own access token scheme, and there's no refresh built in.

EDIT: And to answer your other question, the only way to tell if a user is logged in is to hit an authenticated endpoint and see what the response is. (e.g. /v0/users/current, passing the access token, and if you get a 200 you're logged in, if you get a 401 you're not)

@jvolker
Copy link
Collaborator Author

jvolker commented Nov 9, 2019

Thanks! Would be nice to have a method for that implemented directly into the jsclient.

This works for me:

const OF = new (require("openframe-jsclient"))();
const auth = require("openframe-jsclient/src/auth");

const token = auth.getToken();

fetch(
  "https://api.openframe.io/v0/users/current?access_token=" + token
).then(response => {
  if (response.status == 200) loggedIn = true;
  else if (response.status == 404 || response.status == 401) loggedIn = false;
}

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

2 participants