Skip to content

Commit

Permalink
Missing token on endpoints and contact tab.
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelblink committed Dec 22, 2020
1 parent 749ccfd commit 528a184
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 2 additions & 4 deletions app/livechat/server/api/v1/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import {
LivechatVisitors,
} from '../../../../models';

const createToken = () => Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);

API.v1.addRoute('omnichannel/contact', { authRequired: true }, {
post() {
try {
check(this.bodyParams, {
_id: Match.Maybe(String),
token: String,
name: String,
email: Match.Maybe(String),
phone: Match.Maybe(String),
Expand All @@ -24,9 +23,8 @@ API.v1.addRoute('omnichannel/contact', { authRequired: true }, {
if (this.bodyParams.phone) {
contactParams.phone = { number: this.bodyParams.phone };
}
const contact = Livechat.registerGuest(contactParams);

const data = Object.assign(contactParams, { token: createToken() });
const contact = Livechat.registerGuest(data);
return API.v1.success({ contact });
} catch (e) {
return API.v1.failure(e);
Expand Down
1 change: 1 addition & 0 deletions client/components/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const createToken = () => Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
10 changes: 8 additions & 2 deletions client/omnichannel/directory/ContactForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import CustomFieldsForm from '../../components/CustomFieldsForm';
import { hasAtLeastOnePermission } from '../../../app/authorization';
import { AsyncStatePhase } from '../../hooks/useAsyncState';
import { formsSubscription } from '../../views/omnichannel/additionalForms';
import { createToken } from '../../components/helpers';

const initialValues = {
token: '',
name: '',
email: '',
phone: '',
Expand All @@ -29,9 +31,10 @@ const getInitialValues = (data) => {
return initialValues;
}

const { contact: { name, phone, visitorEmails, livechatData, contactManager } } = data;
const { contact: { name, token, phone, visitorEmails, livechatData, contactManager } } = data;

return {
token: token ?? '',
name: name ?? '',
email: visitorEmails ? visitorEmails[0].address : '',
phone: phone ? phone[0].phoneNumber : '',
Expand Down Expand Up @@ -76,6 +79,7 @@ export function ContactNewEdit({ id, data, reload, close }) {
handleUsername,
} = handlers;
const {
token,
name,
email,
phone,
Expand Down Expand Up @@ -148,8 +152,10 @@ export function ContactNewEdit({ id, data, reload, close }) {

if (id) {
payload._id = id;
payload.token = token;
} else {
payload.token = createToken();
}

if (livechatData) { payload.livechatData = livechatData; }
if (username) { payload.contactManager = { username }; }

Expand Down

0 comments on commit 528a184

Please sign in to comment.