Skip to content

Instantly share code, notes, and snippets.

@thameera
Last active June 8, 2021 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thameera/a8151e8eb6367c0a510c6d8447d34a32 to your computer and use it in GitHub Desktop.
Save thameera/a8151e8eb6367c0a510c6d8447d34a32 to your computer and use it in GitHub Desktop.
Using Auth0-angular's auth.isAuthenticated observable in a service
import { Injectable } from '@angular/core';
import { AuthService } from '@auth0/auth0-angular';
@Injectable({
providedIn: 'root',
})
export class AudioService {
isAuthenticated = false
constructor(
public auth: AuthService,
) {
this.auth.isAuthenticated$.subscribe({
next: (isAuthenticated) => {
this.isAuthenticated = isAuthenticated
},
error: (msg) => {
console.log('error')
}
})
}
test(): void {
if (this.isAuthenticated) {
console.log('Is authenticated')
} else {
console.log('NOT authenticated')
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment