How to Check If User Logged In

Hello. I’ve never worked with authentication before and am new to Okta and although I’ve read the documentation available I’m struggling with understanding how to use Okta.

I have a webpage (e.g urlA) that needs to be secure. I got the sign-in widget working and whenever I type in http://localhost:8080 in a new browser window I see the widget first, sign in, and get redirected to urlA. I can add a redirect so that whenever someone accesses urlA directly (i.e. http://localhost:8080/urlA) it first gets rerouted to the sign-in widget. But how do I check whether a user is already logged in or not so that I can automatically redirect them back to urlA from the sign-in widget so they don’t have to repeatedly keep entering their credentials?

I understand this has something do with Sessions and Authentication but if someone would please explain it to me like I’m a 5 year old with examples I would very very much appreciate it.

Have you gone through this quickstart document that explains how to use the sign in widget? - https://developer.okta.com/quickstart/#/widget/nodejs/generic

If the user already has a session with Okta and you redirect to the login page (with your redirectURL specified as http://localhost/urlA), you will not have to login again. The user will be automatically redirected to your page.

The linked document actually has this code snippet where you actually check if the user has an active session using oktaSignIn.session.get() and render the sign in page only if the user doesn’t an active session.

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