IODPLogin
This provides a common sign in process for all IODP web applications.
Setup
-
Install the package: npm install @iodp/iodp-login OR yarn add @iodp/iodp-login
-
Import IODPLoginModule into your app's Core module: import { IODPLoginModule } from '@iodp/iodp-login';
... imports: [ ... IODPLoginModule ... ], ...
- Navigate to the IODPLoginComponent in your routes: import { IODPLoginComponent } from '@iodp/iodp-login';
const routes: Routes = [ ... { path: 'signin', component: IODPLoginComponent }, ... ]
- Add the AuthGuard to any routes that require a user to be signed in: import { AuthGuard } from '@iodp/iodp-login';
const routes: Routes = [ ... { path: 'project-templates', component: ProjectTemplatesComponent, canActivate: [AuthGuard] }, ... ]
-
Handle the navigation for after successful sign in. The user will be directed to the 'welcome' url: const routes: Routes = [ ... { path: 'welcome', pathMatch: 'full', redirectTo: '/project-templates' }, ... ]
-
Include something like the following in your app's startup service: private _destinationSettings: DestinationObject = { [press F12 to find the needed properties, including if you must select a project] }
private _encryptSettings: EncryptObject = { [press F12 to find the needed properties] }
constructor(private login: IODPLoginService) { this.login.setDestination(this._destinationSettings); this.login.setEncryption(this._encryptSettings); }
- Use the public properties and methods from IODPLoginService: import { User, IODPLoginService } from '@iodp/iodp-login';
project: string user: User privileges: string user$: Subject<User>() errors$: Subject<string>()
constructor(private login: IODPLoginService) { this.project = this.login.currentProject this.user = this.login.currentUser this.user$ = this.login.user$ this.errors$ = this.login.loginMessage$
// ONLY NEED TO USE ONE OF THESE this.privileges = this.login.privileges; // this is synchonous but will not have a value until the login call returns this.checkPrivilege() // this will asynchonously give you the privileges as soon as they are available }
checkPrivilege() { this.login.privilege.subscribe(resp => { [This contains the user's privileges] }) }
logout() { this.login.logout(); this.router.navigate(['/signin']); }