Authentication
Of course, one of the first things a CMS needs is a way for users to authenticate themselves and login. The framework adds a way to do this, by way of an authentication API endpoint. The endpoint is simply "login
". If the login attempt is successful, then the returned data will look like the following:
{ content: 'new token value', expiration: 'timestamp' }
Here's an example:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let userEmail = '...' | |
let userPassword = '...' | |
let self = this | |
fetch("www.mysite.com/api/login", { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ | |
email: userEmail, | |
password: userPassword | |
}) | |
}) | |
.then((blob) => { | |
return blob.json() | |
}) | |
.then((data) => { | |
// the new token will be data.content | |
// the tokens expiration will be data.expiration | |
// make sure you keep track of them! | |
}) |