@invsqr/auth v1.1.4
Installation
Using npm:
npm install @invsqr/auth --save
Setup
In your root module (e.g. AppModule
):
import { AuthModule, AuthService } from "auth";
@NgModule({
declarations: [
...
],
imports: [
...
AuthModule.forRoot({ apiUrl: "...", passwordResetRoute: "...", emailConfirmRoute: "..." })
],
providers: [
...
AuthService
],
bootstrap: [...]
})
export class AppModule { }
AuthModule.forRoot
could, for instance, accept the application's environment file, assuming the environment file contains apiUrl
, passwordResetRoute
and emailConfirmRoute
properties
Usage
Login
In your login template:
...
<input type="email" fdnUsername>
<input type="password" fdnPassword>
<button type="submit" fdnSubmit [submitMode]="SubmitMode.Login" (complete)="submitComplete($event)">Submit</button>
...
fdnUsername
binds the email input's value to the AuthService
, while fdnPassword
binds to the password input, which get submitted for login when click
is detected on the fdnSubmit
button
Other
See SubmitMode
enum for all available submit operations, and the corresponding AuthService
public methods for usage guidelines
enum SubmitMode {
/** POST username and password for login */
Login,
/** POST username, email and password for new account */
Register,
/** GET password reset email */
GetReset,
/** PUT reset token and password for new password */
PutReset,
/** PUT password for new password */
ChangePassword
}
Configuration
The AuthModule.forRoot
should accept an object with project-specific configuration settings
apiUrl
- the root URL of the application APIpasswordResetRoute
- the route that the password reset email will direct the user to and should accept the following path parameters:email
- the user's email address, to pre-populate and prevent them from having to enter themselvescode
- the password reset token that should be included in the PUT request to submit the new passwordemailConfirmRoute
- the route that the email confirmation will direct the user to and should accept the following path parameters:userId
- the user's id; pass this to the AuthService's parameter of the same namecode
- the email confirmation token that should be included in the GET request to confirm the user's email address
Notes
While input validation is left to the devices of the consumer (at least for now), Angular's Reactive Forms are stongly encouraged.