constructor()
Othent JS SDK constructor() function
Instantiate Othent
.
API
options: OthentOptions
options: OthentOptions
Options to customize Othent
's behavior when instantiating it.
Take a look at the TypeScript OthentOptions
and OthentConfig
interfaces on GitHub for additional details.
The following options are available:
appInfo: AppInfo
Must / can contain the following properties:
name: string
Name of your app. This will add a tag
App-Name: <appName>
to any transaction signed or sent usingOthent.sign
,Othent.dispatch
orOthent.signDataItem
.version: string
Version of your app. This will add a tag
App-Version: <appVersion>
to any transaction signed or sent usingOthent.sign
,Othent.dispatch
orOthent.signDataItem
.env: string
Environment 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.dispatch
orOthent.signDataItem
.If no value (empty
string
) is provided, this will automatically be set to"development"
iflocation.hostname = "localhost"
or"production"
otherwise.logo?: UrlString
Image with the logo of your app. Optional and not used for now.
gatewayConfig?: GatewayConfig
Gateway config to connect to Arweave.
persistCookie: boolean | OthentStorageKey
Default:
false
Set this to
true
or 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
true
will set the cookie on client / frontend, but you'll have to manually recover it on the server / backend, and pass it toOthent
'sconstructor
asinitialUserDetails
.persistLocalStorage: boolean | OthentStorageKey
Default:
false
Set this to
true
or the name of thelocalStorage
item 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
refreshTokenExpirationMs
have passed, but will remain inlocalStorage
until the user logs out or until that time has passed andOthent
is instantiated again.initialUserDetails?: UserDetails | null
Initial 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: boolean
Default:
false
Enable additional logs.
inject: boolean
Default:
false
Inject Othent's instance as
globalThis.arweaveWallet
so thatarweave-js
can use it on the background.serverBaseURL: string
API base URL. Needed if you are using a private/self-hosted API and Auth0 tenant.
auth0Domain: string
Auth0 domain. Needed if you are using a private/self-hosted API and Auth0 tenant.
auth0ClientId: string
Auth0 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: Auth0Strategy
Default:
refresh-tokens
Possible 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: Auth0CacheType
Default:
memory
Possible 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 = true
option, the user details (but not the refresh / access tokens) will be persisted inlocalStorage
until 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: Auth0LogInMethod
Default:
popup
Possible 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 orauth0RedirectURI
upon authentication. Once they are redirected back, the URL will show acode
andstate
query parameters for a second or two, until the authentication flow is completed.See:
loginWithRedirect
,handleRedirectCallback
,loginWithPopup
.
auth0RedirectURI: Auth0RedirectUri | null
Default:
location.origin
** (when available in the platform) **Auth0's callback URL (
redirect_uri
) used during the authentication flow.auth0ReturnToURI: Auth0RedirectUri | null
Default:
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: AutoConnect
Default:
lazy
Possible values are:
eager
: Try to log in as soon as the page loads. This won't work when usingauth0Strategy = "refresh-tokens"
andauth0Cache = "memory"
.lazy
Try to log in as soon as anyOthent
method is called. This will only work withauth0Strategy = "refresh-tokens"
andauth0Cache = "memory"
if the calling theOthent
method 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: boolean
Default:
true
All
Othent
methods could throw an error, so you should wrap them intry-catch
blocks. Alternatively, you can set this option tofalse
and 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.dispatch
orOthent.signDataItem
.
Last updated