Skip to content

[Bug]: Guard function 'autoLoginPartialRoutesGuard' is incompatible with the new CanMatchFn of Angular 21.2 #2184

@olivier-robin31

Description

@olivier-robin31

Version

21.0.1

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

ERROR Error: Please provide a configuration before setting up the module
    at _LoginService.login (angular-auth-oidc-client.mjs:5748:13)
    at angular-auth-oidc-client.mjs:6624:22
    at map.js:7:37
    at OperatorSubscriber2._this._next (OperatorSubscriber.js:15:21)
    at Subscriber2.next (Subscriber.js:34:18)
    at Observable2._subscribe (innerFrom.js:51:24)
    at Observable2._trySubscribe (Observable.js:38:25)
    at Observable.js:32:31
    at errorContext (errorContext.js:19:9)
    at Observable2.subscribe (Observable.js:23:9)

Steps to reproduce the behavior

With an Angular 21.2 application, setting the guard function `autoLoginPartialRoutesGuard` as a CanMatchFn, like this:

"canMatch: [autoLoginPartialRoutesGuard],"

raises the above Error at runtime.

A clear and concise description of what you expected to happen.

We expect the guard to launch the `checkAuth`, and if not authenticated redirect to the IDP provider.

Additional context

Angular has changed the CanMatchFn in Angular 21.2 (adding of a new 3rd parameter).

Here is the type in Angular 20:
https://v20.angular.dev/api/router/CanMatchFn

type CanMatchFn = (route: Route, segments: UrlSegment[]) => MaybeAsync<GuardResult>;

And here is the new one in Angular 21.2:
https://angular.dev/api/router/CanMatchFn

type CanMatchFn = (route: Route, segments: UrlSegment[], currentSnapshot?: PartialMatchRouteSnapshot) => MaybeAsync<GuardResult>;

The lib has signed the guard function with 3 parameters, the last one being just for internal purpose:
https://github.com/damienbod/angular-auth-oidc-client/blob/main/projects/angular-auth-oidc-client/src/lib/auto-login/auto-login-partial-routes.guard.ts#L76
Now Angular calls this function with a new 3rd parameter (currentSnapshot), the lib makes a confusion and thinks it is the configId. Of course it is not, and then we get a configuration to null into the checkAuth function:
https://github.com/damienbod/angular-auth-oidc-client/blob/main/projects/angular-auth-oidc-client/src/lib/auto-login/auto-login-partial-routes.guard.ts#L122
Finally, this null value configuration is passed to the LoginService in the method login, that raises the Error 'Please provide a configuration before setting up the module'.
https://github.com/damienbod/angular-auth-oidc-client/blob/main/projects/angular-auth-oidc-client/src/lib/login/login.service.ts#L23

NOTE: the problem is not present when using canActivate (because it still has only 2 parameters)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions