Coder Social home page Coder Social logo

Comments (7)

david-on-github avatar david-on-github commented on August 10, 2024 1

It should, can you provide more details.

It's not very clear in the docs but a call needs to be made to the facade service getOidcUser() method somewhere to check if the user is in storage. This could be done in the entry route, a parent route, a service, a guard, etc. Depends on the requirements of your app.

from ng-oidc-client.

839928622 avatar 839928622 commented on August 10, 2024

does this library works on Angular 9 ? same issue happend to me on Angular 9

from ng-oidc-client.

839928622 avatar 839928622 commented on August 10, 2024

It should, can you provide more details.

It's not very clear in the docs but a call needs to be made to the facade service getOidcUser() method somewhere to check if the user is in storage. This could be done in the entry route, a parent route, a service, a guard, etc. Depends on the requirements of your app.

I copy following blocks code,it did't work,when console.log('Auth Guard - Checking if user exists', user),it shows null on console ,but I actualy can see the user access_token and profile in localstorage,did I miss something importent?
those are a couple of code that I copyed :
export class OidcGuardService implements CanActivate {
constructor(private router: Router, private oidcFacade: OidcFacade) {}

public canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | boolean {
return this.oidcFacade.identity$.pipe(
take(1),
switchMap(user => {
console.log('Auth Guard - Checking if user exists', user);
console.log('Auth Guard - Checking if user is expired:', user && user.expired);
if (user && !user.expired) {
return of(true);
} else {
this.router.navigate(['/login']);
return of(false);
}
})
);
}
}

from ng-oidc-client.

david-on-github avatar david-on-github commented on August 10, 2024

GetOidcUser() should be called before trying to access identity$ if you are expecting a value for identity. This dispatches an event to retrieve and set the property. This should be done prior to checking in an auth guard.

identity$ just returns the current value of the identity in the store as observable. Whether it was set or not.

GetOidcUser() will look into the cache and set the user if one exists. It also sets the loading flag while it resolves it.

waitForAuthenticationLoaded() is just a function for waiting until the loading flag becomes false, if not already.

from ng-oidc-client.

839928622 avatar 839928622 commented on August 10, 2024

I enject OidcFacade to AuthGuarad,and call this.oidcFacade.GetOidcUser(),still can not retrieve user access_token and profile ,when I flick back to localstorage ,I can see user access_token and pfofile.
you can check my source code on :
https://github.com/839928622/ERP-Angular-WebApp/blob/master/src/app/Guards/auth.guard.ts
line 14

from ng-oidc-client.

Alex-Torres avatar Alex-Torres commented on August 10, 2024

I think the issue may be related to where you may be pulling user information Local or Session Storage. I think the library by default pulls from Session Storage. When I updated the CallBack.html:

If you don't define:
userStore: new WebStorageStateStore({ store: window.localStorage })

In the NgOidcClientModule.ForRoot({})

The ngrx will read user information from Session Storage by default.

from ng-oidc-client.

david-on-github avatar david-on-github commented on August 10, 2024

Please provide repro if this is still an issue. Thanks

from ng-oidc-client.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.