createClient(options)
creates a new CloudAuthClient for the application with appId
.
import { createClient } from '@featherscloud/auth'
const appId = '<your-app-id>'
const auth = createClient({ appId })
This error is thrown when the client requires a user login and usually used to put together the URL for the login page:
import { LoginRequiredError } from '@featherscloud/auth'
try {
const authorizationHeader = await auth.getHeader()
}
catch (error: unknown) {
if (error instanceof LoginRequiredError) {
// Redirect to the login page
window.location.href = await auth.getLoginUrl(error)
}
else {
throw error
}
}
IndexedDb
) - The storage for device information and access tokens.15 minutes
) - The time (in seconds) a login request expires. Can not be more than 15 minutes.auth.getAccessToken()
returns the access token for the user. Will throw a LoginRequiredError
if the user needs to log in for this device.
auth.getHeaders()
returns the Authorization
header for the current user in the required form of Bearer <accessToken>
.
auth.getLoginUrl(error)
returns the URL for the login page when a LoginRequiredError
happened.
auth.logout()
logs the user out but remembers their device so their information is pre-filled the next time they log in.
auth.logoutAndForget()
logs the user out and deletes this device.
auth.listDevices()
lists all devices in the store. This can be used to handle account switching.
auth.createDevice()
creates a new devices and sets it as the currently used device. This will require a user to log in before they can make any requests.
auth.getDevice()
returns the information (like the device id and linked user) for the current device.
auth.setDevice(deviceId)
sets the currently used device (usually retrieved from auth.listDevices()
).
createVerifier({ appId })
creates a verifier for the application id. It does not need any additional information, works offline and does not make any external requests.
import { createVerifier } from '@featherscloud/auth'
const appId = '<your-app-id>'
const verifier = createVerifier({ appId })
Once initialized the following methods are available.
verifier.verifyToken(accessToken [, additionalPayload])
verifies a Cloud Auth access token.
verifier.verifyToken(authorizationHeader [, additionalPayload])
verifies an Authorization
header.