UBuilder Auth (vue2)
For vue 3, uses @ubuilder/auth.
UBuilder 8 not compatible with version 7.
* User authentication and autorization.
Authorized request should use Auth.rest() or this.$rest.
Installation
``
npm i @ubuilder/auth
`
Usage
`
javascript
import Vue from 'vue';
import Auth from '@ubuilder/auth-vue2';const options = {/ plugin options /};
Vue.use(Auth, options);
``
Options
* baseURL: string - Base URL for UBuilder auth server. Default value is '/api/auth'.
* apiURL: string - Base URL for API server. Default value is '/'.
* storageKey: string - LocalStorage key for current user. Default value is 'ubuilder:user'.
Provides
* $auth: Auth - Auth API
* $user: User - computed value of current user.
* $rest: Rest - Rest API supports authorization.
$3
* login(username: string, password: string, remember?: boolean): Promise<User> - login process
* logout(): Promise<void> - logout process
* currentUser(): User - get current reactive user. If not logged in, returns anonymous user - check by isLoggedIn property.
* rest(): Rest - get @ubuilder/rest API for authorized API request.
$3
* token: string - Access token for UBuilder server.
* expireAt: number - expire time
* authorities: string[] - array of authority.
* details: Record<string, unknown> - UserDetails from UBuidler auth server.
* isLoggedIn: boolean - determine user is logged in.
* hasAuthority(authority?: string): boolean - determine user has authority. When needs track user changes, should use computed.