Angular
This tutorial demonstrates how to add user login to an Angular application using BlitzWare.
Last updated
Was this helpful?
This tutorial demonstrates how to add user login to an Angular application using BlitzWare.
Last updated
Was this helpful?
You will need some details about your application to communicate with BlitzWare. You can get these details from the Application Settings section in the BlitzWare dashboard.
You need the Client ID.
A redirect URI is a URL in your application where BlitzWare redirects the user after they have authenticated. The redirect URI for your app must be added to the Redirect URIs list in your Application Settings under the Security tab. If this is not set, users will be unable to log in to the application and will get an error.
The SDK exposes several types that help you integrate BlitzWare with your Angular application idiomatically, including a module and an authentication service.
The SDK exports provideBlitzWareAuth
, which is a provide function that contains all the services required for the SDK to function. To register this with your application:
Open the app.config.ts
file.
Import the provideBlitzWareAuth
function from the blitzware-angular-sdk
package.
Add provideBlitzWareAuth
to the application by adding it to the providers
array.
The provideBlitzWareAuth
function takes the properties clientId
and redirectUri
; the values of these properties correspond to the Client ID and Redirect URI values that you can find under Settings in the Single Page Web Application (SPA) that you registered with BlitzWare.
The BlitzWare Angular SDK gives you tools to quickly implement user authentication in your Angular application, such as creating a login button using the login()
method from the BlitzWareAuthService
service class. Executing login()
redirects your users to the BlitzWare Universal Login Page, where BlitzWare can authenticate them. Upon successful authentication, BlitzWare will redirect your users back to your application.
The BlitzWare Angular SDK helps you retrieve the profile information associated with logged-in users quickly in whatever component you need, such as their name or profile picture, to personalize the user interface. The profile information is available through currentUser
exposed by the BlitzWareAuthService
service.
You also need a way to log out. You can create a logout button using the logout()
method from the BlitzWareAuthService
service. Executing logout()
clears the session and makes sure that the user can not access protected resources.
Take this Dashboard
component as an example of how to use it:
The BlitzWare Angular SDK exports the BlitzWareAuthGuard
class used to protect routes by preventing unauthorized users from accessing certain pages or components within your application. Here is how you can do it:
As you can see, we simply added BlitzWareAuthGuard
between the canActivate
brackets.
That's it!
Run the following command within your project directory to install the :