Redirect login if localstorage isn't null

Hello! I've created a app to show dashboards, and i created a login page.

This login, initialy, have only a userid. I wanna bypass login if localstorage isn't null, if user already passed by page another time.

How can i check if localstorage isn't null and redirect util.openApp?

Thanks!

Hi @igordisco,

I'm assuming you have a separate app for Login & Dashboard and a user can land on the login app through multiple journeys.

I would create a Module that holds all of that logic and sets localStorage so you can share that easily across apps.

For the problem at hand, I would check localStorage on pageLoad and if the userId is set, redirect directly (not waiting for the submit button). If you want to run that check on submit, I would create a JS query that holds that logic (instead of binding everything to the submit handler).

Something like

if (localStorage.values?.userId == null) {
  localStorage.setValue('userId', 'whateverYouSet')
} else {
  utils.openApp('XXXXXXXX-XXXXX', { newTab: true })
}

Let me know if that makes sense.

Works like a charm!

2 Likes