new AxiosJwtAuthService(options)
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Implements:
- AuthService
- Source:
Methods
addAuthenticationToHttpClient(newHttpClient, config) → {HttpClient}
Adds authentication defaults and interceptors to an HTTP client instance.
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
newHttpClient |
HttpClient | |||||||||||||||||
config |
Object |
Properties
|
- Source:
Returns:
A configured Axios HTTP client.
- Type
- HttpClient
applyMiddleware(middleware)
Applies middleware to the axios instances in this service.
Parameters:
Name | Type | Description |
---|---|---|
middleware |
Array | Middleware to apply. |
- Source:
(async) ensureAuthenticatedUser(redirectUrlopt) → {Promise.<UserData>}
Ensures a user is authenticated. It will redirect to login when not authenticated.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
redirectUrl |
string |
<optional> |
config.BASE_URL | to return user after login when not authenticated. |
- Source:
Returns:
- Type
- Promise.<UserData>
(async) fetchAuthenticatedUser() → {Promise.<UserData>|Promise.<null>}
Reads the authenticated user's access token. Resolves to null if the user is unauthenticated.
- Source:
Returns:
Resolves to the user's access token if they are logged in.
- Type
- Promise.<UserData> | Promise.<null>
getAuthenticatedHttpClient(optionsopt) → {HttpClient}
Gets the authenticated HTTP client for the service. This is an axios instance.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Optional options for how the HTTP client should be configured. Properties
|
- Source:
Returns:
A configured axios http client which can be used for authenticated requests.
- Type
- HttpClient
getAuthenticatedUser() → {UserData|null}
If it exists, returns the user data representing the currently authenticated user. If the user is anonymous, returns null.
- Source:
Returns:
- Type
- UserData | null
getHttpClient(optionsopt) → {HttpClient}
Gets the unauthenticated HTTP client for the service. This is an axios instance.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Optional options for how the HTTP client should be configured. Properties
|
- Source:
Returns:
A configured axios http client.
- Type
- HttpClient
getLoginRedirectUrl(redirectUrl)
Builds a URL to the login page with a post-login redirect URL attached as a query parameter.
const url = getLoginRedirectUrl('http://localhost/mypage');
console.log(url); // http://localhost/login?next=http%3A%2F%2Flocalhost%2Fmypage
Parameters:
Name | Type | Description |
---|---|---|
redirectUrl |
string | The URL the user should be redirected to after logging in. |
- Source:
getLogoutRedirectUrl(redirectUrl)
Builds a URL to the logout page with a post-logout redirect URL attached as a query parameter.
const url = getLogoutRedirectUrl('http://localhost/mypage');
console.log(url); // http://localhost/logout?next=http%3A%2F%2Flocalhost%2Fmypage
Parameters:
Name | Type | Description |
---|---|---|
redirectUrl |
string | The URL the user should be redirected to after logging out. |
- Source:
(async) hydrateAuthenticatedUser() → {Promise.<null>}
Fetches additional user account information for the authenticated user and merges it into the existing authenticatedUser object, available via getAuthenticatedUser().
console.log(authenticatedUser); // Will be sparse and only contain basic information.
await hydrateAuthenticatedUser()
const authenticatedUser = getAuthenticatedUser();
console.log(authenticatedUser); // Will contain additional user information
- Source:
Returns:
- Type
- Promise.<null>
redirectToLogin(redirectUrl)
Redirects the user to the login page.
Parameters:
Name | Type | Description |
---|---|---|
redirectUrl |
string | The URL the user should be redirected to after logging in. |
- Source:
redirectToLogout(redirectUrl)
Redirects the user to the logout page.
Parameters:
Name | Type | Description |
---|---|---|
redirectUrl |
string | The URL the user should be redirected to after logging out. |
- Source:
setAuthenticatedUser(authUser)
Sets the authenticated user to the provided value.
Parameters:
Name | Type | Description |
---|---|---|
authUser |
UserData |
- Source: