adds login and register local operations

This commit is contained in:
James
2020-08-12 16:40:51 -04:00
parent 3c025377f5
commit f8840ee8b7
10 changed files with 91 additions and 6 deletions

View File

@@ -0,0 +1,7 @@
const register = require('./register');
const login = require('./login');
module.exports = {
register,
login,
};

View 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;

View 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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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}

View File

@@ -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;

View File

@@ -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,
};

View File

@@ -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;