WriteJwt(userinfo) Last updated: 07. Sep 2023
API only function
The writeJwt function is responsible for generating and writing a JWT (JSON Web Token) secure cookie to the user's browser.
Parameters
Name | Type | Description |
---|---|---|
userinfo | object | A JSON object with all neccessary info about user. Will be stored in an encrypted cookie. |
Returns
True if successfull.
Example
Code example (JS)
JS is normal JavaScript either running in the browser or on the Docly™ server.docly.writeJwt({ "username" : username, "access" : "admin" });
// In all other API functions read the value from the request.Jwt
if (request.Jwt.access != "admin")
return docly.denyAccess();
// To log the user out again, write a NULL value
docly.writeJwt(null);
// *********************************
// A full login.js example:
let user = docly.getFile("#/Users/" + form.username);
if (user != null && user.PasswordHash == form.passwordHash) {
let userinfo = {
"Username" : form.username,
"AccessLevel" : user.AccessLevel
};
docly.writeJwt(userinfo);
return true;
} else {
return false;
}