I have a forum like application that uses Laravel for the back-end, sanctum for authentication and Angular for the front-end
I need guest users to access the home page and request the list of questions to show from the Laravel api but I need to prevent them from accessing the editor page for creating questions
the api endpoints are protected by auth:sanctum
middleware so guest users need to request a token to access the api.
Instead Users authenticated also via front-end (logged in Users) should access guests forbidden routes.
For logged in users I've created this guard in angular:
export class AuthGuardGuard implements CanActivate {
constructor(private authService : AuthService){ }
activate = false
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
this.authService.getUser()
.subscribe(
res => this.activate = true
)
return this.activate;
}
}
but it's not clear to me how should I handle guest users authentications