adds login and register local operations
This commit is contained in:
7
src/auth/operations/local/index.js
Normal file
7
src/auth/operations/local/index.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const register = require('./register');
|
||||
const login = require('./login');
|
||||
|
||||
module.exports = {
|
||||
register,
|
||||
login,
|
||||
};
|
||||
28
src/auth/operations/local/login.js
Normal file
28
src/auth/operations/local/login.js
Normal file
@@ -0,0 +1,28 @@
|
||||
async function login(options) {
|
||||
const {
|
||||
collection: collectionSlug,
|
||||
res,
|
||||
depth,
|
||||
locale,
|
||||
fallbackLocale,
|
||||
data,
|
||||
} = options;
|
||||
|
||||
const collection = this.collections[collectionSlug];
|
||||
|
||||
return this.operations.collections.auth.login({
|
||||
depth,
|
||||
collection,
|
||||
overrideAccess: true,
|
||||
data,
|
||||
req: {
|
||||
payloadAPI: 'local',
|
||||
locale,
|
||||
fallbackLocale,
|
||||
payload: this,
|
||||
},
|
||||
res,
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = login;
|
||||
26
src/auth/operations/local/register.js
Normal file
26
src/auth/operations/local/register.js
Normal file
@@ -0,0 +1,26 @@
|
||||
async function register(options) {
|
||||
const {
|
||||
collection: collectionSlug,
|
||||
depth,
|
||||
locale,
|
||||
fallbackLocale,
|
||||
data,
|
||||
} = options;
|
||||
|
||||
const collection = this.collections[collectionSlug];
|
||||
|
||||
return this.operations.collections.auth.register({
|
||||
depth,
|
||||
data,
|
||||
collection,
|
||||
overrideAccess: true,
|
||||
req: {
|
||||
payloadAPI: 'local',
|
||||
locale,
|
||||
fallbackLocale,
|
||||
payload: this,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = register;
|
||||
@@ -86,7 +86,7 @@ async function login(args) {
|
||||
cookieOptions.secure = true;
|
||||
}
|
||||
|
||||
if (args.req.headers.origin && args.req.headers.origin.indexOf('localhost') === -1) {
|
||||
if (args.req.headers && args.req.headers.origin && args.req.headers.origin.indexOf('localhost') === -1) {
|
||||
let domain = args.req.headers.origin.replace('https://', '');
|
||||
domain = domain.replace('http://', '');
|
||||
cookieOptions.domain = domain;
|
||||
|
||||
@@ -41,7 +41,7 @@ async function refresh(args) {
|
||||
cookieOptions.secure = true;
|
||||
}
|
||||
|
||||
if (args.req.headers.origin && args.req.headers.origin.indexOf('localhost') === -1) {
|
||||
if (args.req.headers && args.req.headers.origin && args.req.headers.origin.indexOf('localhost') === -1) {
|
||||
let domain = args.req.headers.origin.replace('https://', '');
|
||||
domain = domain.replace('http://', '');
|
||||
cookieOptions.domain = domain;
|
||||
|
||||
@@ -80,7 +80,7 @@ async function resetPassword(args) {
|
||||
cookieOptions.secure = true;
|
||||
}
|
||||
|
||||
if (args.req.headers.origin && args.req.headers.origin.indexOf('localhost') === -1) {
|
||||
if (args.req.headers && args.req.headers.origin && args.req.headers.origin.indexOf('localhost') === -1) {
|
||||
let domain = args.req.headers.origin.replace('https://', '');
|
||||
domain = domain.replace('http://', '');
|
||||
cookieOptions.domain = domain;
|
||||
|
||||
@@ -29,8 +29,9 @@ const Group = (props) => {
|
||||
<FieldTypeGutter />
|
||||
|
||||
<div className={`${baseClass}__content-wrapper`}>
|
||||
<h2 className={`${baseClass}__title`}>{label}</h2>
|
||||
|
||||
{label && (
|
||||
<h2 className={`${baseClass}__title`}>{label}</h2>
|
||||
)}
|
||||
<div className={`${baseClass}__fields-wrapper`}>
|
||||
<RenderFields
|
||||
readOnly={readOnly}
|
||||
|
||||
@@ -6,9 +6,13 @@
|
||||
}
|
||||
|
||||
.group {
|
||||
margin: base(2) 0;
|
||||
margin-bottom: base(2);
|
||||
display: flex;
|
||||
|
||||
&__title {
|
||||
margin-top: base(2);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
.field-type-gutter__content-container {
|
||||
box-shadow: #{$style-stroke-width-m} 0px 0px 0px $color-dark-gray;
|
||||
|
||||
@@ -4,10 +4,13 @@ const create = require('./create');
|
||||
const update = require('./update');
|
||||
const localDelete = require('./delete');
|
||||
|
||||
const authOperations = require('../../../auth/operations/local');
|
||||
|
||||
module.exports = {
|
||||
find,
|
||||
findOne,
|
||||
create,
|
||||
update,
|
||||
localDelete,
|
||||
auth: authOperations,
|
||||
};
|
||||
|
||||
16
src/index.js
16
src/index.js
@@ -91,6 +91,10 @@ class Payload {
|
||||
this.router.use(errorHandler(this.config));
|
||||
|
||||
if (typeof options.onInit === 'function') options.onInit();
|
||||
|
||||
this.find = this.find.bind(this);
|
||||
this.register = this.register.bind(this);
|
||||
this.login = this.login.bind(this);
|
||||
}
|
||||
|
||||
async sendEmail(message) {
|
||||
@@ -113,6 +117,18 @@ class Payload {
|
||||
find = find.bind(this);
|
||||
return find(options);
|
||||
}
|
||||
|
||||
async register(options) {
|
||||
let { register } = localOperations.auth;
|
||||
register = register.bind(this);
|
||||
return register(options);
|
||||
}
|
||||
|
||||
async login(options) {
|
||||
let { login } = localOperations.auth;
|
||||
login = login.bind(this);
|
||||
return login(options);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Payload;
|
||||
|
||||
Reference in New Issue
Block a user