-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
/** | ||
* An application role. | ||
* | ||
* Is used in the client to decide which content a user can view. | ||
*/ | ||
export type AuthRole = string; | ||
|
||
/** | ||
* A set of auth roles for a user. | ||
*/ | ||
export type AuthRoleSet = Set<AuthRole>; | ||
|
||
/** | ||
* Auth role for a full admin. Is allowed into all sections of the app. | ||
*/ | ||
export const AUTH_APP_ADMIN_ROLE = 'admin'; | ||
|
||
/** | ||
* Auth role for a general user. Is allowed into the app and is logged in. | ||
*/ | ||
export const AUTH_APP_USER_ROLE = 'user'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
|
||
/** | ||
* An application user state. | ||
* | ||
* Generic states that define the current state of the user: | ||
* - none: the user is not logged in | ||
* - anon: the user is logged in as an anonymous account | ||
* - error: there was an error loading the correct user state | ||
* - new: the user has a full account but has not completed onboarding/setup | ||
* - user: the user has a full account and has completed setup | ||
*/ | ||
export type AuthUserState = 'none' | 'anon' | 'new' | 'user' | 'error'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './service'; | ||
export * from './auth.state'; | ||
export * from './auth.role'; |
12 changes: 12 additions & 0 deletions
12
packages/dbx-core/src/lib/auth/service/auth.service.rxjs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { isNot, onTrueToFalse } from '@dereekb/rxjs'; | ||
import { map, Observable, scan } from 'rxjs'; | ||
|
||
/** | ||
* Convenience operator that emits events when the input observable goes from true to false. | ||
* | ||
* @param isLoggedInObs | ||
* @returns | ||
*/ | ||
export function signedOutEventFromIsLoggedIn(isLoggedInObs: Observable<boolean>): Observable<void> { | ||
return isLoggedInObs.pipe(onTrueToFalse(), map(_ => undefined)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Observable } from 'rxjs'; | ||
import { AuthRoleSet } from '../auth.role'; | ||
import { AuthUserState } from '../auth.state'; | ||
|
||
/** | ||
* Client auth service used to retrieve info about the current state of client authentication and client roles they may have. | ||
*/ | ||
export abstract class DbxAuthService { | ||
|
||
/** | ||
* Whether or not the client is logged in. | ||
* | ||
* A user is considered logged in even if there is an anonymous user. For more detailed info, consider using authUserState$. | ||
*/ | ||
abstract readonly isLoggedIn$: Observable<boolean>; | ||
|
||
/** | ||
* Emits an event every time the user was signed in but signs out. | ||
*/ | ||
abstract readonly signedOut$: Observable<void>; | ||
|
||
/** | ||
* Current state of the user. | ||
*/ | ||
abstract readonly authUserState$: Observable<AuthUserState>; | ||
|
||
/** | ||
* Role set for the current user. | ||
*/ | ||
abstract readonly authRoles$: Observable<AuthRoleSet>; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './auth.service.rxjs'; | ||
export * from './auth.service'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters