Skip to content

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

Open

Description

@jvolker

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.

Activity

  1. jmwohl commented on Nov 5, 2019

    @jmwohl
    Member

    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)

  2. jvolker commented on Nov 9, 2019

    @jvolker
    CollaboratorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions