Auth
authorize users to use your cyxth instance
import Auth from '@cyxth/auth'
const APP_ID = 'YOUR_APP_ID';
const PRIVATE_KEY = env(PRIVATE_KEY);
const auth = new AUTH(APP_ID,PRIVATE_KEY);
const user = {
id: "alice"
}
const token = auth.createToken(user,{duration: '4h' })
// send token to frontend
console.log(token)
// and we get something like
// {token: "eyJhbGciOi.............-b0FjCQqTUEb_lHo2eUAUMdXgvRAA",}
index
constructors
methods
Constructors
constructor
new Auth (appId: string, privateKey: string) : Auth ;use this in your authorization server to allow your user to access your cyxth instance.
Parameters
appId
your cyxth app id
stringprivateKey
EdDsa private key
stringReturns
AuthMethods
createToken
createToken (user: UserInfo, options?: TokenOptions) : Promise<TokenData> ;create a user authorization token
this is the token data used to authorize users in the frontend by the cyxth.connect function
Parameters
Returns
TokenData
Promise<TokenData>