0

We have an angular 11 app deployed as Azure Static Web App. The Auth Guard is implemented and WORKING IN LOCAL that means running in VS with F5 everything is fine. However, on Azure, trying to access an unauthorized page result in a 404 not found rather than the redirection to the login page as it is implemented.

Here's the AuthGuard component:

import { Injectable } from "@angular/core";
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from "@angular/router";

import { AuthenticationService } from "../services/authentication.service";

@Injectable({
    providedIn: "root"
})
export class AuthGuard implements CanActivate {
    constructor(private router: Router, private authenticationService: AuthenticationService) { }

    canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
        if (this.authenticationService.currentTokenValue) {
            return true;
        }

        void this.router.navigate(["/account/login"]);
        return false;
    }
}

The way we test locally is to run the app then open another tab and go to a page without login first and we're redirected to the login page as expected.

Are we missing something somewhere for the redirection to work on Azure?

Marc Roussel
  • 459
  • 9
  • 20
  • can you navigate to any part of the application? a 404 sounds like the static files are not where you think there are. I would try removing the auth guard and seeing if navigation works before assuming you have an issue with the guard. – ye-olde-dev Aug 09 '22 at 15:04
  • I can effectively navigate all right in all the application on Azure. Only when I try a direct link to a page that is giving the 404 otherwise FROM the application everything is fine – Marc Roussel Aug 09 '22 at 15:06
  • Removing the auth guard would imply that even in local it isn't working which it is am I right ? – Marc Roussel Aug 09 '22 at 15:08
  • This is not a guard issue probably. You need to configure your server to handle SPA links. – MikeOne Aug 09 '22 at 16:03
  • I don't specifically say it's auth guard but only that the redirection is in there and nowhere else that's why I mentioned it. I'm more concerned about the redirection not working in Azure but working locally! – Marc Roussel Aug 09 '22 at 20:50

0 Answers0