Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where's the code that redirects to /login? #15

Closed
jssoriao opened this issue Dec 23, 2020 · 1 comment
Closed

Where's the code that redirects to /login? #15

jssoriao opened this issue Dec 23, 2020 · 1 comment
Assignees

Comments

@jssoriao
Copy link

I'm trying to understand the root-application.js but cannot understand where's the code that redirects to /login when user's not authenticated. Can you help me understand it more?

@jualoppaz
Copy link
Owner

Hi @jsoriao ! You are not able to find that code because it's not located in this repo 😄 .

As you can see in root-application.js file, the unique single-spa application that is mounted only in logged in routes is the single-spa-layout-app. For this reason, I decided to locate in that repository the needed code for redirect to login page if you try to access to a protected route without the required grants, in this case a simple JWT token.

You can find the code here:

https://github.com/jualoppaz/single-spa-layout-app/blob/master/src/App.vue#L23

beforeCreate() {
    if (!sessionStorage.getItem('token')) {
      window.history.pushState(null, null, '/login');
    }
    ...
}

I did it by this way for the reason I explained you, but you can choose so many other strategies like listening all route changes in your own root-applications.js file. It all depends on developer decision as there is no single-spa official way.

Hope this guidelines be useful for you.

@jualoppaz jualoppaz pinned this issue Dec 28, 2020
@jualoppaz jualoppaz self-assigned this Dec 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants