Login page check


#1

Goodmorning everyone,
as you can exit routes when the user is not logged in.
I modified the kitchen-sink example but it does not work.

This is the code:

var routes = [
...
...
   // Components
   {
     path: '/ accordion /',
    
async (routeTo, routeFrom, resolve, reject) {
if (sessionStorage! == undefined) {
resolve ({url: './pages/accordion.html'})
} else {
resolve ({url: './pages/login-screen-page.html'})
}
}
   },

...
...

];

Thanks for help.

Michele.


#2

this is illegal:
if (sessionStorage! == undefined)
it should be:
if (sessionStorage !== undefined)
or better:
if (sessionStorage.length)


#3
{
  path:'/login/',
  componentUrl:'./pages/login-screen-page.html'
},
{
  path:'/accordion/',
  url:'./pages/accordion.html',
},
{
  path:'/check/',
  redirect:function(route,resolve,reject){
    resolve(sessionStorage.length?'/accordion/':'/login/');
  }
}

#4

Thanks for the reply.
I made the change, but still does not go to the correct page after the test. In practice, if the user is not logged in he never goes to the instruction: resolve ({url: ‘./pages/login-screen-page.html’})


#5

I’ve also tried this, but I can not do what I want.
In practice, using the kitchen-sink (v.2.0.5) example I would like the page / accordion / or any other one open only if you have logged in, otherwise it must always ask for login. Maybe I do not have the right level yet to fully understand this framework.

I apologize for my terrible English.

Thank you for your interest.

Michele.


#6

sorry
that will do it
i just checked
it works

{
  path:'/accordion/',
  url:sessionStorage.length?'./pages/accordion.html','./pages/buttons.html',
},

#7

I made this change:

// Components
{
// path: ‘/accordion/’,
// url: ‘./pages/accordion.html’,
path:’/accordion/’,
componentUrl:sessionStorage.length?’./pages/accordion.html’:’./pages/login-screen-page.html’,
},

but after logging in if I click on / accordion / continue to open the login even if the sessionStorage is enhanced.

I checked via: console.log (sessionStorage.user);

Grazie. Michele.


#8

now i get you
sorry for everything
you need to use the option that you provide

{
  path:'/accordion/',
  async(routeTo, routeFrom, resole, reject) {
    if (sessionStorage.length) {
      resolve({url:'./pages/accordion.html'})
    } else {
      resolve({componentUrl:'./pages/login-screen-page.html'})
    }
  }
}

#9

Hurray now works. I had already tried the async function, but without result.
Maybe because I always used componentUrl.
In any case, thank you very much for your help.
Now you need a little imagination to make a good application.

Michele Lo Monaco.


#10

Good morning,
I continued my tests by adding a php page with the session in order to differentiate a result, but until I force a page refresh I never see the effect of the session variable: $ _SESSION [“mioutente”]

I put the project in my web space.

kitchen-sink.rar (right click)

The page in the menu is: Pagina Test

Can you give me a tip.

Thank you.

Michele.


[V2] How to route into page when app initialise?
Select root view based on some condition
#11

sessionStorage doesn’t related to $_SESSION, sessionStorage is the client only


#12

Thank you.
So all login must be managed by client?

There is an example online that we can consult.

Michele.


#13

No, there is a ton of ways to handle it, in most cases when auth is server side, then usually on app launch you can do a request to server to verify that you are logged in.


#14

Or, with every request you can send additional auth header with token or something else