mirror of
https://github.com/strapi/strapi.git
synced 2025-07-24 17:40:18 +00:00
45 lines
782 B
JavaScript
45 lines
782 B
JavaScript
const { createRequest } = require('./request');
|
|
|
|
const auth = {
|
|
username: 'admin',
|
|
email: 'admin@strapi.io',
|
|
password: 'pcw123',
|
|
};
|
|
|
|
const rq = createRequest();
|
|
|
|
const register = async () => {
|
|
await rq({
|
|
url: '/admin/auth/local/register',
|
|
method: 'POST',
|
|
body: auth,
|
|
}).catch(err => {
|
|
if (err.error.message.includes("You can't register a new admin")) return;
|
|
throw err;
|
|
});
|
|
};
|
|
|
|
const login = async () => {
|
|
const { body } = await rq({
|
|
url: '/admin/login',
|
|
method: 'POST',
|
|
body: {
|
|
email: auth.email,
|
|
password: auth.password,
|
|
},
|
|
});
|
|
|
|
return body.data;
|
|
};
|
|
|
|
module.exports = {
|
|
async registerAndLogin() {
|
|
// register
|
|
await register();
|
|
|
|
// login
|
|
const { token } = await login();
|
|
return token;
|
|
},
|
|
};
|