# I want to know how to check if users are logged in

**URL:** <https://community.auth0.com/t/i-want-to-know-how-to-check-if-users-are-logged-in/64920>\
**Category:** Get Help\
**Created:** [June 23, 2021, 9:27am UTC](https://community.auth0.com/t/i-want-to-know-how-to-check-if-users-are-logged-in/64920 "2021-06-23T09:27:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nnahito](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nnahito/32/15686_2.png) [@nnahito](https://community.auth0.com/u/nnahito)\
**Post date:** [June 23, 2021, 9:27am UTC](https://community.auth0.com/t/i-want-to-know-how-to-check-if-users-are-logged-in/64920/1 "2021-06-23T09:27:02Z")

</div>

How can I check if users are logged in using the API in a smartphone application or single page application?

For example, in Laravel, we can use Auth::check() to check if the user is logged in.

How do I implement this in my API?  
I would appreciate it if you could tell me.

Thank you very much.

---

<div class="post-metadata">

**Author:** ![sgo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgo/32/13789_2.png) [@sgo](https://community.auth0.com/u/sgo)\
**Post date:** [June 23, 2021, 4:55pm UTC](https://community.auth0.com/t/i-want-to-know-how-to-check-if-users-are-logged-in/64920/3 "2021-06-23T16:55:35Z")

</div>

Hi @nnahito ,

The SPA SDKs have `getTokenSilently` which performs a silent authentication in a hidden iframe to check if the user has a valid session. If they do, tokens will be returned, if they have been logged out, you will get a “Login required” error which would indicate the user no longer has a session with Auth0.

- [Auth0 Single Page App SDK](https://auth0.com/docs/libraries/auth0-single-page-app-sdk#get-access-token-with-no-interaction)
- [https://auth0.github.io/auth0-spa-js/classes/auth0client.html#gettokensilently](https://auth0.github.io/auth0-spa-js/classes/auth0client.html#gettokensilently)
- [Configure Silent Authentication](https://auth0.com/docs/authorization/configure-silent-authentication)

Mobile apps will typically make use of refresh tokens on the other hand to keep the user “logged in”:

- [GitHub - auth0/Auth0.swift: Auth0 SDK for Apple platforms](https://github.com/auth0/Auth0.swift#next-steps)
- [Refresh Tokens](https://auth0.com/docs/tokens/refresh-tokens)

---

<div class="post-metadata">

**Author:** ![nnahito](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nnahito/32/15686_2.png) [@nnahito](https://community.auth0.com/u/nnahito)\
**Post date:** [June 24, 2021, 1:40am UTC](https://community.auth0.com/t/i-want-to-know-how-to-check-if-users-are-logged-in/64920/4 "2021-06-24T01:40:07Z")

</div>

Thank you for your answer.  
I see that the SDK has something called getTokenSilently.

Is there any way to check this via the PHP API?  
I will eventually create the app, but I want to run it in PHP first to see how it works.

For example, if I run the API in PHP, it will check if the user is logged in.

---

<div class="post-metadata">

**Author:** ![sgo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgo/32/13789_2.png) [@sgo](https://community.auth0.com/u/sgo)\
**Post date:** [June 25, 2021, 2:34pm UTC](https://community.auth0.com/t/i-want-to-know-how-to-check-if-users-are-logged-in/64920/5 "2021-06-25T14:34:59Z")

</div>

I believe the closest equivalent in the PHP SDK is the `getUser` method:

[Auth0-PHP Readme](https://github.com/auth0/auth0-PHP/blob/978ee208377c6f0e811a17ebd41bf01ef306e23d/README.md#authentication-api)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [July 10, 2021, 2:35pm UTC](https://community.auth0.com/t/i-want-to-know-how-to-check-if-users-are-logged-in/64920/6 "2021-07-10T14:35:48Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
