Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pages/login-success.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const LoginSuccess = ({ t, r }) => {
cookies.set('token', t, {
path: '/',
expires: new Date(Date.now() + 7776e6),
secure: false,
secure: true,
httpOnly: false,
sameSite: 'none',
});
Expand Down
27 changes: 16 additions & 11 deletions src/api/article.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import axios from 'axios';
axios.defaults.withCredentials = true;

const axiosInstance = axios.create({
withCredentials: true,
});

const getMainArticles = async ({ page = 0, limit = 6 }) => {
try {
const { data } = await axios.get(
const { data } = await axiosInstance.get(
`${process.env.APP_API_URL}/articles?page=${page}&limit=${limit}`,
{}
);
Expand All @@ -15,11 +20,11 @@ const getMainArticles = async ({ page = 0, limit = 6 }) => {
const getPublishedArticles = async ({ page = 0, limit = 6 }) => {
try {
const token = localStorage.getItem('token');
const { data, status } = await axios.get(
const { data, status } = await axiosInstance.get(
`${process.env.APP_API_URL}/articles/published?page=${page}&limit=${limit}`,
{
headers: { authorization: `Bearer ${token}` },
'Content-Type': 'application/json'
'Content-Type': 'application/json',
}
);
return data;
Expand All @@ -37,11 +42,11 @@ const getPublishedArticles = async ({ page = 0, limit = 6 }) => {
const getDraftArticles = async ({ page = 0, limit = 6 }) => {
try {
const token = localStorage.getItem('token');
const { data } = await axios.get(
const { data } = await axiosInstance.get(
`${process.env.APP_API_URL}/articles/drafts?page=${page}&limit=${limit}`,
{
headers: { authorization: `Bearer ${token}` },
'Content-Type': 'application/json'
'Content-Type': 'application/json',
}
);
return data;
Expand All @@ -56,9 +61,9 @@ const getDraftArticles = async ({ page = 0, limit = 6 }) => {
}
};

const getArticle = async slug => {
const getArticle = async (slug) => {
try {
const { data } = await axios.get(
const { data } = await axiosInstance.get(
`${process.env.APP_API_URL}/articles/${slug}`,
{}
);
Expand All @@ -68,15 +73,15 @@ const getArticle = async slug => {
}
};

const deleteArticle = async slug => {
const deleteArticle = async (slug) => {
const token = localStorage.getItem('token');

try {
const { data } = await axios.delete(
const { data } = await axiosInstance.delete(
`${process.env.APP_API_URL}/articles/${slug}`,
{
headers: { authorization: `Bearer ${token}` },
'Content-Type': 'application/json'
'Content-Type': 'application/json',
}
);
return data;
Expand All @@ -90,5 +95,5 @@ export {
getPublishedArticles,
getDraftArticles,
getArticle,
deleteArticle
deleteArticle,
};