mirror of
https://github.com/plankanban/planka.git
synced 2025-07-27 17:19:43 +02:00
feat: Store accessToken in cookies instead of localStorage
This commit is contained in:
parent
cad3233da7
commit
7ef55ec578
27 changed files with 137 additions and 114 deletions
|
@ -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,
|
||||
|
|
|
@ -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),
|
||||
}));
|
||||
|
|
|
@ -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),
|
||||
}));
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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: {
|
||||
|
@ -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),
|
||||
}));
|
||||
|
|
|
@ -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),
|
||||
}));
|
||||
|
|
|
@ -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]);
|
||||
|
||||
|
@ -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) => ({
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 }) => {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -3,27 +3,25 @@ import socket from './socket';
|
|||
|
||||
/* Actions */
|
||||
|
||||
const getUsers = (headers) => socket.get('/users', undefined, headers);
|
||||
const getUsers = () => socket.get('/users');
|
||||
|
||||
const createUser = (data, headers) => socket.post('/users', data, headers);
|
||||
const createUser = (data) => socket.post('/users', data);
|
||||
|
||||
const getUser = (id, headers) => socket.get(`/users/${id}`, undefined, headers);
|
||||
const getUser = (id) => socket.get(`/users/${id}`);
|
||||
|
||||
const getCurrentUser = (headers) => socket.get('/users/me', undefined, headers);
|
||||
const getCurrentUser = () => socket.get('/users/me');
|
||||
|
||||
const updateUser = (id, data, headers) => socket.patch(`/users/${id}`, data, headers);
|
||||
const updateUser = (id, data) => socket.patch(`/users/${id}`, data);
|
||||
|
||||
const updateUserEmail = (id, data, headers) => socket.patch(`/users/${id}/email`, data, headers);
|
||||
const updateUserEmail = (id, data) => socket.patch(`/users/${id}/email`, data);
|
||||
|
||||
const updateUserPassword = (id, data, headers) =>
|
||||
socket.patch(`/users/${id}/password`, data, headers);
|
||||
const updateUserPassword = (id, data) => socket.patch(`/users/${id}/password`, data);
|
||||
|
||||
const updateUserUsername = (id, data, headers) =>
|
||||
socket.patch(`/users/${id}/username`, data, headers);
|
||||
const updateUserUsername = (id, data) => socket.patch(`/users/${id}/username`, data);
|
||||
|
||||
const updateUserAvatar = (id, data, headers) => http.post(`/users/${id}/avatar`, data, headers);
|
||||
const updateUserAvatar = (id, data) => http.post(`/users/${id}/avatar`, data);
|
||||
|
||||
const deleteUser = (id, headers) => socket.delete(`/users/${id}`, undefined, headers);
|
||||
const deleteUser = (id) => socket.delete(`/users/${id}`);
|
||||
|
||||
export default {
|
||||
getUsers,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue