constructor()
Othent JS SDK constructor() function
Instantiate Othent.
API
constructor(
options: OthentOptions,
): Othent;options: OthentOptions
options: OthentOptionsOptions to customize Othent's behavior when instantiating it.
The following options are available:
appInfo: AppInfoMust / can contain the following properties:
name: stringName of your app. This will add a tag
App-Name: <appName>to any transaction signed or sent usingOthent.sign,Othent.dispatchorOthent.signDataItem.version: stringVersion of your app. This will add a tag
App-Version: <appVersion>to any transaction signed or sent usingOthent.sign,Othent.dispatchorOthent.signDataItem.env: stringEnvironment your app is currently running on (e.g. "development", "staging", "production", ...). This will add a tag
App-Env: <appEnv>to any transaction signed or sent usingOthent.sign,Othent.dispatchorOthent.signDataItem.If no value (empty
string) is provided, this will automatically be set to"development"iflocation.hostname = "localhost"or"production"otherwise.logo?: UrlStringImage with the logo of your app. Optional and not used for now.
gatewayConfig?: GatewayConfigGateway config to connect to Arweave.
persistCookie: boolean | OthentStorageKeyDefault:
falseSet this to
trueor the name of the cookie where you'd like the user details JSON to be stored. Useful when you use SSR and need to user details to be available on the server.The cookie will expire after
refreshTokenExpirationMs.Note setting this option to
truewill set the cookie on client / frontend, but you'll have to manually recover it on the server / backend, and pass it toOthent'sconstructorasinitialUserDetails.persistLocalStorage: boolean | OthentStorageKeyDefault:
falseSet this to
trueor the name of thelocalStorageitem where you'd like the user details JSON to be stored. Useful to immediately sync user details and authentication status across tabs, and to make it look to users as if they were already authenticated when coming back to your app beforerefreshTokenExpirationMs, even if the session still needs to be refreshed by callingconnect()orrequireAuth().The stored values will be removed / discarded if more than
refreshTokenExpirationMshave passed, but will remain inlocalStorageuntil the user logs out or until that time has passed andOthentis instantiated again.initialUserDetails?: UserDetails | nullInitial user details. Useful for server-side rendered sites or native apps that might store the most recent user details externally (e.g. cookie or
SharedPreferences).debug: booleanDefault:
falseEnable additional logs.
inject: booleanDefault:
falseInject Othent's instance as
globalThis.arweaveWalletso thatarweave-jscan use it on the background.serverBaseURL: stringAPI base URL. Needed if you are using a private/self-hosted API and Auth0 tenant.
auth0Domain: stringAuth0 domain. Needed if you are using a private/self-hosted API and Auth0 tenant.
auth0ClientId: stringAuth0 client ID. Needed if you are using a private/self-hosted API and Auth0 tenant, or if you have a dedicated App inside Othent's Auth0 tenant to personalize the logic experience (premium subscription).
auth0Strategy: Auth0StrategyDefault:
refresh-tokensPossible values are:
refresh-tokens: Use refresh tokens for authentication. This is the most secure and robust option.cross-site-cookies: Use cross-site cookies for authentication. Not recommended, as this won't work in browsers that block cross-site cookies, such as Brave.
auth0Cache: Auth0CacheTypeDefault:
memoryPossible values are:
memory: This is the most secure and recommended option/location to store tokens, but new tabs won't be able to automatically log in using a popup without a previous user action.However, by setting the
persistLocalStorage = trueoption, the user details (but not the refresh / access tokens) will be persisted inlocalStorageuntil the most recent refresh token's expiration date, allowing you to read the user details (.getUserDetails()/.getSyncUserDetails()) and make it look in the UI as if the user were already logged in.localstorage: Store tokenslocalStorage. This makes it possible for new tabs to automatically log in using a popup, even after up to 2 weeks of inactivity (i.e. "keep me logged in"), but offers a larger attack surface to attackers trying to get a hold of the refresh / access tokens.custom: Provide a custom storage implementation that implements Auth0'sICache. Useful for mobile apps (e.g. React Native).
auth0LogInMethod: Auth0LogInMethodDefault:
popupPossible values are:
popup: Open Auth0's authentication page on a popup window while the original page just waits for authentication to take place or to timeout. This option is faster and less intrusive.redirect: Navigate to Auth0's authentication page, which will redirect users back to your site orauth0RedirectURIupon authentication. Once they are redirected back, the URL will show acodeandstatequery parameters for a second or two, until the authentication flow is completed.See:
loginWithRedirect,handleRedirectCallback,loginWithPopup.
auth0RedirectURI: Auth0RedirectUri | nullDefault:
location.origin** (when available in the platform) **Auth0's callback URL (
redirect_uri) used during the authentication flow.auth0ReturnToURI: Auth0RedirectUri | nullDefault:
location.origin** (when available in the platform) **Auth0's logout URL (
returnTo) used during the logout flow.auth0RefreshTokenExpirationMs: number:Default:
1296000000(2 weeks)Refresh token expiration in milliseconds. This should/must match the value set in Auth0. On the client, this value is only used to set a timer to automatically log out users when their refresh token expires. Incorrectly setting this value will make users think they are still logged in, even after their refresh token expires (until they try to perform any kind of action through Othent and get an error).
autoConnect: AutoConnectDefault:
lazyPossible values are:
eager: Try to log in as soon as the page loads. This won't work when usingauth0Strategy = "refresh-tokens"andauth0Cache = "memory".lazyTry to log in as soon as anyOthentmethod is called. This will only work withauth0Strategy = "refresh-tokens"andauth0Cache = "memory"if the calling theOthentmethod is preceded by a user action (e.g. click on a button).off: Do not log in automatically. Trying to perform any action through Othent before callingconnect()orrequireAuth()will result in an error.
throwErrors: booleanDefault:
trueAll
Othentmethods could throw an error, so you should wrap them intry-catchblocks. Alternatively, you can set this option tofalseand the library will do this automatically, so no method will ever throw an error. In this case, however, you must add at least one error event listener withothent.addEventListener("error", () => { ... }).tags: TagData[]Default:
[]Additional tags to include in transactions signed or sent using
Othent.sign,Othent.dispatchorOthent.signDataItem.
Last updated