Skip to content

Commit

Permalink
feat: Store accessToken in cookies instead of localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
meltyshev committed Apr 26, 2022
1 parent 536064f commit 486e663
Show file tree
Hide file tree
Showing 27 changed files with 137 additions and 114 deletions.
14 changes: 14 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"i18next": "^21.6.16",
"i18next-browser-languagedetector": "^6.1.4",
"initials": "^3.1.2",
"js-cookie": "^3.0.1",
"lodash": "^4.17.20",
"node-sass": "^7.0.1",
"prop-types": "^15.8.1",
Expand Down
2 changes: 1 addition & 1 deletion client/src/api/access-tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import http from './http';

/* Actions */

const createAccessToken = (data, headers) => http.post('/access-tokens', data, headers);
const createAccessToken = (data) => http.post('/access-tokens', data);

export default {
createAccessToken,
Expand Down
4 changes: 2 additions & 2 deletions client/src/api/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const transformAction = (action) => ({

/* Actions */

const getActions = (cardId, data, headers) =>
socket.get(`/cards/${cardId}/actions`, data, headers).then((body) => ({
const getActions = (cardId, data) =>
socket.get(`/cards/${cardId}/actions`, data).then((body) => ({
...body,
items: body.items.map(transformAction),
}));
Expand Down
12 changes: 6 additions & 6 deletions client/src/api/attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ export const transformAttachment = (attachment) => ({

/* Actions */

const createAttachment = (cardId, data, requestId, headers) =>
http.post(`/cards/${cardId}/attachments?requestId=${requestId}`, data, headers).then((body) => ({
const createAttachment = (cardId, data, requestId) =>
http.post(`/cards/${cardId}/attachments?requestId=${requestId}`, data).then((body) => ({
...body,
item: transformAttachment(body.item),
}));

const updateAttachment = (id, data, headers) =>
socket.patch(`/attachments/${id}`, data, headers).then((body) => ({
const updateAttachment = (id, data) =>
socket.patch(`/attachments/${id}`, data).then((body) => ({
...body,
item: transformAttachment(body.item),
}));

const deleteAttachment = (id, headers) =>
socket.delete(`/attachments/${id}`, undefined, headers).then((body) => ({
const deleteAttachment = (id) =>
socket.delete(`/attachments/${id}`).then((body) => ({
...body,
item: transformAttachment(body.item),
}));
Expand Down
7 changes: 3 additions & 4 deletions client/src/api/board-memberships.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import socket from './socket';

/* Actions */

const createBoardMembership = (boardId, data, headers) =>
socket.post(`/boards/${boardId}/memberships`, data, headers);
const createBoardMembership = (boardId, data) =>
socket.post(`/boards/${boardId}/memberships`, data);

const deleteBoardMembership = (id, headers) =>
socket.delete(`/board-memberships/${id}`, undefined, headers);
const deleteBoardMembership = (id) => socket.delete(`/board-memberships/${id}`);

export default {
createBoardMembership,
Expand Down
11 changes: 5 additions & 6 deletions client/src/api/boards.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import { transformAttachment } from './attachments';

/* Actions */

const createBoard = (projectId, data, headers) =>
socket.post(`/projects/${projectId}/boards`, data, headers);
const createBoard = (projectId, data) => socket.post(`/projects/${projectId}/boards`, data);

const getBoard = (id, headers) =>
socket.get(`/boards/${id}`, undefined, headers).then((body) => ({
const getBoard = (id) =>
socket.get(`/boards/${id}`).then((body) => ({
...body,
included: {
...body.included,
Expand All @@ -17,9 +16,9 @@ const getBoard = (id, headers) =>
},
}));

const updateBoard = (id, data, headers) => socket.patch(`/boards/${id}`, data, headers);
const updateBoard = (id, data) => socket.patch(`/boards/${id}`, data);

const deleteBoard = (id, headers) => socket.delete(`/boards/${id}`, undefined, headers);
const deleteBoard = (id) => socket.delete(`/boards/${id}`);

export default {
createBoard,
Expand Down
6 changes: 2 additions & 4 deletions client/src/api/card-labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import socket from './socket';

/* Actions */

const createCardLabel = (cardId, data, headers) =>
socket.post(`/cards/${cardId}/labels`, data, headers);
const createCardLabel = (cardId, data) => socket.post(`/cards/${cardId}/labels`, data);

const deleteCardLabel = (cardId, labelId, headers) =>
socket.delete(`/cards/${cardId}/labels/${labelId}`, undefined, headers);
const deleteCardLabel = (cardId, labelId) => socket.delete(`/cards/${cardId}/labels/${labelId}`);

export default {
createCardLabel,
Expand Down
7 changes: 3 additions & 4 deletions client/src/api/card-memberships.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import socket from './socket';

/* Actions */

const createCardMembership = (cardId, data, headers) =>
socket.post(`/cards/${cardId}/memberships`, data, headers);
const createCardMembership = (cardId, data) => socket.post(`/cards/${cardId}/memberships`, data);

const deleteCardMembership = (cardId, userId, headers) =>
socket.delete(`/cards/${cardId}/memberships?userId=${userId}`, undefined, headers);
const deleteCardMembership = (cardId, userId) =>
socket.delete(`/cards/${cardId}/memberships?userId=${userId}`);

export default {
createCardMembership,
Expand Down
20 changes: 10 additions & 10 deletions client/src/api/cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export const transformCardData = (data) => ({

/* Actions */

const getCards = (boardId, data, headers) =>
socket.get(`/board/${boardId}/cards`, data, headers).then((body) => ({
const getCards = (boardId, data) =>
socket.get(`/board/${boardId}/cards`, data).then((body) => ({
...body,
items: body.items.map(transformCard),
included: {
Expand All @@ -45,26 +45,26 @@ const getCards = (boardId, data, headers) =>
},
}));

const createCard = (boardId, data, headers) =>
socket.post(`/boards/${boardId}/cards`, transformCardData(data), headers).then((body) => ({
const createCard = (boardId, data) =>
socket.post(`/boards/${boardId}/cards`, transformCardData(data)).then((body) => ({
...body,
item: transformCard(body.item),
}));

const getCard = (id, headers) =>
socket.get(`/cards/${id}`, undefined, headers).then((body) => ({
const getCard = (id) =>
socket.get(`/cards/${id}`).then((body) => ({
...body,
item: transformCard(body.item),
}));

const updateCard = (id, data, headers) =>
socket.patch(`/cards/${id}`, transformCardData(data), headers).then((body) => ({
const updateCard = (id, data) =>
socket.patch(`/cards/${id}`, transformCardData(data)).then((body) => ({
...body,
item: transformCard(body.item),
}));

const deleteCard = (id, headers) =>
socket.delete(`/cards/${id}`, undefined, headers).then((body) => ({
const deleteCard = (id) =>
socket.delete(`/cards/${id}`).then((body) => ({
...body,
item: transformCard(body.item),
}));
Expand Down
12 changes: 6 additions & 6 deletions client/src/api/comment-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ import { transformAction } from './actions';

/* Actions */

const createCommentAction = (cardId, data, headers) =>
socket.post(`/cards/${cardId}/comment-actions`, data, headers).then((body) => ({
const createCommentAction = (cardId, data) =>
socket.post(`/cards/${cardId}/comment-actions`, data).then((body) => ({
...body,
item: transformAction(body.item),
}));

const updateCommentAction = (id, data, headers) =>
socket.patch(`/comment-actions/${id}`, data, headers).then((body) => ({
const updateCommentAction = (id, data) =>
socket.patch(`/comment-actions/${id}`, data).then((body) => ({
...body,
item: transformAction(body.item),
}));

const deleteCommentAction = (id, headers) =>
socket.delete(`/comment-actions/${id}`, undefined, headers).then((body) => ({
const deleteCommentAction = (id) =>
socket.delete(`/comment-actions/${id}`).then((body) => ({
...body,
item: transformAction(body.item),
}));
Expand Down
4 changes: 2 additions & 2 deletions client/src/api/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const http = {};

// TODO: add all methods
['POST'].forEach((method) => {
http[method.toLowerCase()] = (url, data, headers) => {
http[method.toLowerCase()] = (url, data) => {
const formData = Object.keys(data).reduce((result, key) => {
result.append(key, data[key]);

Expand All @@ -15,8 +15,8 @@ const http = {};

return fetch(`${Config.SERVER_BASE_URL}/api${url}`, {
method,
headers,
body: formData,
...Config.FETCH_OPTIONS,
})
.then((response) =>
response.json().then((body) => ({
Expand Down
7 changes: 3 additions & 4 deletions client/src/api/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import socket from './socket';

/* Actions */

const createLabel = (boardId, data, headers) =>
socket.post(`/boards/${boardId}/labels`, data, headers);
const createLabel = (boardId, data) => socket.post(`/boards/${boardId}/labels`, data);

const updateLabel = (id, data, headers) => socket.patch(`/labels/${id}`, data, headers);
const updateLabel = (id, data) => socket.patch(`/labels/${id}`, data);

const deleteLabel = (id, headers) => socket.delete(`/labels/${id}`, undefined, headers);
const deleteLabel = (id) => socket.delete(`/labels/${id}`);

export default {
createLabel,
Expand Down
7 changes: 3 additions & 4 deletions client/src/api/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import socket from './socket';

/* Actions */

const createList = (boardId, data, headers) =>
socket.post(`/boards/${boardId}/lists`, data, headers);
const createList = (boardId, data) => socket.post(`/boards/${boardId}/lists`, data);

const updateList = (id, data, headers) => socket.patch(`/lists/${id}`, data, headers);
const updateList = (id, data) => socket.patch(`/lists/${id}`, data);

const deleteList = (id, headers) => socket.delete(`/lists/${id}`, undefined, headers);
const deleteList = (id) => socket.delete(`/lists/${id}`);

export default {
createList,
Expand Down
11 changes: 5 additions & 6 deletions client/src/api/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { transformAction } from './actions';

/* Actions */

const getNotifications = (headers) =>
socket.get('/notifications', undefined, headers).then((body) => ({
const getNotifications = () =>
socket.get('/notifications').then((body) => ({
...body,
included: {
...body.included,
Expand All @@ -14,8 +14,8 @@ const getNotifications = (headers) =>
},
}));

const getNotification = (id, headers) =>
socket.get(`/notifications/${id}`, undefined, headers).then((body) => ({
const getNotification = (id) =>
socket.get(`/notifications/${id}`).then((body) => ({
...body,
included: {
...body.included,
Expand All @@ -24,8 +24,7 @@ const getNotification = (id, headers) =>
},
}));

const updateNotifications = (ids, data, headers) =>
socket.patch(`/notifications/${ids.join(',')}`, data, headers);
const updateNotifications = (ids, data) => socket.patch(`/notifications/${ids.join(',')}`, data);

export default {
getNotifications,
Expand Down
7 changes: 3 additions & 4 deletions client/src/api/project-managers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import socket from './socket';

/* Actions */

const createProjectManager = (projectId, data, headers) =>
socket.post(`/projects/${projectId}/managers`, data, headers);
const createProjectManager = (projectId, data) =>
socket.post(`/projects/${projectId}/managers`, data);

const deleteProjectManager = (id, headers) =>
socket.delete(`/project-managers/${id}`, undefined, headers);
const deleteProjectManager = (id) => socket.delete(`/project-managers/${id}`);

export default {
createProjectManager,
Expand Down
14 changes: 7 additions & 7 deletions client/src/api/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import socket from './socket';

/* Actions */

const getProjects = (headers) => socket.get('/projects', undefined, headers);
const getProjects = () => socket.get('/projects');

const createProject = (data, headers) => socket.post('/projects', data, headers);
const createProject = (data) => socket.post('/projects', data);

const getProject = (id, headers) => socket.get(`/projects/${id}`, undefined, headers);
const getProject = (id) => socket.get(`/projects/${id}`);

const updateProject = (id, data, headers) => socket.patch(`/projects/${id}`, data, headers);
const updateProject = (id, data) => socket.patch(`/projects/${id}`, data);

const updateProjectBackgroundImage = (id, data, headers) =>
http.post(`/projects/${id}/background-image`, data, headers);
const updateProjectBackgroundImage = (id, data) =>
http.post(`/projects/${id}/background-image`, data);

const deleteProject = (id, headers) => socket.delete(`/projects/${id}`, undefined, headers);
const deleteProject = (id) => socket.delete(`/projects/${id}`);

export default {
getProjects,
Expand Down
3 changes: 1 addition & 2 deletions client/src/api/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ const { socket } = io;
socket.connect = socket._connect; // eslint-disable-line no-underscore-dangle

['GET', 'POST', 'PUT', 'PATCH', 'DELETE'].forEach((method) => {
socket[method.toLowerCase()] = (url, data, headers) =>
socket[method.toLowerCase()] = (url, data) =>
new Promise((resolve, reject) => {
socket.request(
{
method,
data,
headers,
url: `/api${url}`,
},
(_, { body, error }) => {
Expand Down
6 changes: 3 additions & 3 deletions client/src/api/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import socket from './socket';

/* Actions */

const createTask = (cardId, data, headers) => socket.post(`/cards/${cardId}/tasks`, data, headers);
const createTask = (cardId, data) => socket.post(`/cards/${cardId}/tasks`, data);

const updateTask = (id, data, headers) => socket.patch(`/tasks/${id}`, data, headers);
const updateTask = (id, data) => socket.patch(`/tasks/${id}`, data);

const deleteTask = (id, headers) => socket.delete(`/tasks/${id}`, undefined, headers);
const deleteTask = (id) => socket.delete(`/tasks/${id}`);

export default {
createTask,
Expand Down
Loading

0 comments on commit 486e663

Please sign in to comment.