Auth
Functions and types relating to the authentication of users in the Telestion frontend.
Note that in most cases, you don’t need to import anything from this package directly, since auth*n is already handled by the framework itself.
Example¶
Classes¶
LoginError¶
Extends¶
Constructors¶
new LoginError()¶
Parameters¶
messages¶
Returns¶
Overrides¶
Error.constructor
Properties¶
message¶
Inherited from¶
Error.message
messages¶
name¶
Inherited from¶
Error.name
stack?¶
Inherited from¶
Error.stack
prepareStackTrace()?¶
Optional override for formatting stack traces
Parameters¶
err¶
stackTraces¶
CallSite
[]
Returns¶
any
See¶
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from¶
Error.prepareStackTrace
stackTraceLimit¶
Inherited from¶
Error.stackTraceLimit
Methods¶
captureStackTrace()¶
Create .stack property on a target object
Parameters¶
targetObject¶
object
constructorOpt?¶
Returns¶
void
Inherited from¶
Error.captureStackTrace
Interfaces¶
ErrorMessages¶
Properties¶
natsUrlMessage?¶
passwordMessage?¶
usernameMessage?¶
User¶
A logged-in user.
Properties¶
natsUrl¶
The NATS URL that the user is connected to.
username¶
The user’s username.
Functions¶
attemptAutoLogin()¶
Attempt to auto-login using credentials stored in sessionStorage.
The credentials will automatically be cleared if they are invalid, the session ends, or logout is called.
Credentials are automatically stored updated by login and logout.
Returns¶
Promise
<boolean
>
true if auto-login was successful, false otherwise
getNatsConnection()¶
Returns¶
null
| NatsConnection
getUser()¶
Returns the user object if the user is currently logged in, else returns null
if no user is currently logged in.
Returns¶
null
| User
isLoggedIn()¶
Checks if a user is logged in.
Returns¶
boolean
true
if the user is logged in, false
otherwise.
login()¶
Logs in a user with the given credentials.
Parameters¶
natsUrl¶
string
The url to connect to the NATS server.
username¶
string
The username for authentication.
password¶
string
The password for authentication.
Returns¶
A promise that resolves once the user is logged in. The resolved value is the logged-in user object.
Throws¶
Error If the provided credentials are incorrect.
logout()¶
Logs out the user if currently logged in.
Returns¶
Promise
<void
>
A promise that resolves once the user is logged out.
~~setAutoLoginCredentials()~~¶
Sets credentials with which to auto-login.
If an auto-login attempt fails, the credentials will be cleared for the remainder of the session and a login form shown to the user. If the user logs in successfully, the credentials will be updated.
Security Warning¶
Use this function only if user authentication is handled by a separate system. Calling this function in your application means your NATS credentials will be hard-coded into your application, which is a security risk.
Parameters¶
credentials¶
The credentials to store
natsUrl¶
string
= ...
The URL of the NATS server to connect to.
password¶
string
= ...
The password to use when connecting to the NATS server.
username¶
string
= ...
The username to use when connecting to the NATS server.
Returns¶
void
Deprecated¶
No, this won’t be removed anytime soon. You can ignore this warning if you’re aware of the security implications.
setNatsConnection()¶
Parameters¶
nc¶
null
| NatsConnection
Returns¶
void
setUser()¶
Sets a new user object or null
if the user is no longer logged in.
Parameters¶
user¶
the user object or null
null
| User
Returns¶
void
useNatsSubscription()¶
Parameters¶
subject¶
string
callback¶
(message
) => void
| Promise
<void
>
options?¶
Returns¶
void
References¶
useNats¶
Re-exports useNats