-1
I am migrating an application from Angular 8 and a great difficulty that I am having is in the routing system, in my application and mandatory this logged in for all routes except for login and registration routes, in Angularjs I used to make this rule in the app.run() I checked if the user was logged in and allowed or denied redirecting to the route, the low code has a simple example of how this was done
var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl : "main.htm"
})
.when("/red", {
templateUrl : "red.htm"
})
.when("/green", {
templateUrl : "green.htm"
})
.when("/blue", {
templateUrl : "blue.htm"
});
});
app.run(function(authService) {
//aqui eu fazia a regra que se ele nao estivesse logado eu jogava ele pra rota de login
});
at Angular 8 I am not able to restrict the user in the right way by the frontend only by the backend, and I wanted to do this by the front, because my served does not take many requests, then for me it is impractical every time the user accesses a route I go there in the backend check if it is logged and send the confinement, I already have the token and the user data stored in a global variable within a service, however I am only able to restrict the user after he already accessed the route and started the controller so I check if he has the token in the global variable and if I don’t have it I play it to another route, and I wanted it to be done already in the module that provides the routes as I did in the Angularjs, this is possible?
search for things canActivate and [Authguard]
– LeAndrade