I am using auth gaurd to prevent URL manipulation in my angular application and redirecting URL manipulation to login page. But it is causing a problem and that is even after successful login, on refreshing the webpage it considers it as URL manipulation and logs the user out by redirecting to the login page.Please note I am not using JWT or any similar kind of authenication mechanism. It's a vanilla authentication based on password returned by the backend DB.I am aslo not mantaining any session till now. Below I am attaching the snippet where I have mapped the path to the routes :
const appRoutes: Routes = [
{ path: '', component: LoginComponent },
{ path: 'dashboard', canActivate: [AuthGuard], component: DashboardComponent },
{ path: 'file-uploader', canActivate: [AuthGuard], component: FileUploaderComponent },
{ path: 'register', component: RegisterComponent },
{ path: 'login', component: LoginComponent }
];
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private user: UserService, private router: Router) {}
canActivate() {
if (this.user.getUserLoggedIn()) {
return true;
}
else
return false;
}
}
Please help me resolve this issue.Thanks in advance.