Vue
This tutorial demonstrates how to add user login to an Vue application using BlitzWare.
Last updated
Was this helpful?
This tutorial demonstrates how to add user login to an Vue 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.
To use the SDK in your Vue application, register the plugin with your Vue application by passing the return value of createBlitzWareAuth
to app.use()
.
The createBlitzWareAuth
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.
To add login to your application, use the login()
function that is exposed on the return value of useBlitzWareAuth
, which you can access in your component's setup()
function. 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.
If you are using the Options API, you can use the same login()
method from the global $blitzware
property through the this
accessor.
Once the user authenticates, the SDK extracts the user's profile information and stores it in memory. It can be accessed by using the reactive user
property exposed by the return value of useBlitzWareAuth
, which you can access in your component's setup()
function.
You also need a way to log out. Use the logout()
function that is exposed on the return value of useBlitzWareAuth
, which you can access in your component's setup()
function, to log the user out of your application. Executing logout()
clears the session and makes sure that the user can not access protected resources.
Take this Dashboard
view as an example of how to use it:
If you are using the Options API, you can use the same user
property and logout()
method from the global $blitzware
property through the this
accessor.
The BlitzWare Vue SDK exports the createBlitzWareAuthGuard
function used to protect routes by preventing unauthorized users from accessing certain pages or components within your application. Here is how you can do it:
That's it!
Run the following command within your project directory to install the :
The plugin will register the SDK using both provide
and app.config.globalProperties
, allowing the SDK to be used with both the and .