Fix auth cookie persist path (#20)
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "patch",
|
||||
"comment": "fix bug of perist cookie",
|
||||
"packageName": "@zhishuyun/hub",
|
||||
"email": "cqc@cuiqingcai.com",
|
||||
"dependentChangeType": "patch"
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export const ENV_LOCAL = 'local';
|
||||
export const ENV_TEST = 'test';
|
||||
export const ENV_PRODUCTION = 'production';
|
||||
@@ -1,4 +1,3 @@
|
||||
export const ERROR_CODE_UNVERIFIED = 'unverified';
|
||||
export const ERROR_CODE_DUPLICATION = 'duplication';
|
||||
export const ERROR_CODE_BUSY = 'busy';
|
||||
export const ERROR_CODE_API_ERROR = 'api_error';
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
export * from './errorCode';
|
||||
export * from './env';
|
||||
export * from './endpoint';
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import router, { ROUTE_AUTH_LOGIN } from '@/router';
|
||||
import store from '@/store';
|
||||
import { getBaseUrlData } from '@/utils';
|
||||
import axios, { AxiosInstance } from 'axios';
|
||||
@@ -10,16 +9,13 @@ const httpClient: AxiosInstance = axios.create({
|
||||
'Content-type': 'application/json',
|
||||
Accept: 'application/json'
|
||||
},
|
||||
paramsSerializer: function (params) {
|
||||
paramsSerializer(params) {
|
||||
return qs.stringify(params, { arrayFormat: 'repeat' });
|
||||
}
|
||||
});
|
||||
|
||||
httpClient.interceptors.request.use((config) => {
|
||||
const accessToken = store.state.token?.access;
|
||||
if (!config.headers) {
|
||||
config.headers = {};
|
||||
}
|
||||
if (accessToken) {
|
||||
config.headers['Authorization'] = `Bearer ${accessToken}`;
|
||||
}
|
||||
@@ -33,12 +29,6 @@ httpClient.interceptors.response.use(
|
||||
(error) => {
|
||||
if (error?.response?.status === 401) {
|
||||
store.dispatch('resetToken');
|
||||
// router.push({
|
||||
// name: ROUTE_AUTH_LOGIN,
|
||||
// query: {
|
||||
// redirect: router?.currentRoute?.value?.path
|
||||
// }
|
||||
// });
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
import { defineComponent } from 'vue';
|
||||
import { IUser } from '@/operators';
|
||||
import { IToken } from '@/operators/auth/models';
|
||||
import { ROUTE_AUTH_LOGIN } from '@/router';
|
||||
|
||||
interface IData {
|
||||
accessToken: string | undefined;
|
||||
@@ -41,6 +40,7 @@ export default defineComponent({
|
||||
await this.$router.push(this.redirect);
|
||||
}
|
||||
} else {
|
||||
// reset token and trigger popup login window
|
||||
this.$store.dispatch('resetToken');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,14 @@ export const initializeCookies = () => {
|
||||
// parse the query string and set to cookies
|
||||
const query = new URLSearchParams(window.location.search);
|
||||
const inviterId = query.get('inviter_id');
|
||||
const expiration = new Date();
|
||||
expiration.setDate(expiration.getDate() + 7);
|
||||
console.log('set INVITER_ID to cookies', inviterId);
|
||||
setCookie('INVITER_ID', inviterId, {
|
||||
expires: expiration
|
||||
});
|
||||
if (inviterId) {
|
||||
// set the cookie to expire in 7 days
|
||||
const expiration = new Date();
|
||||
expiration.setDate(expiration.getDate() + 7);
|
||||
console.log('set INVITER_ID to cookies', inviterId);
|
||||
setCookie('INVITER_ID', inviterId, {
|
||||
expires: expiration,
|
||||
path: '/'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user