Fix auth cookie persist path (#20)

This commit is contained in:
AceDataCloud committed 2024-01-03 11:32:32 +08:00
1 parent 636b98e003
commit 1e1becd8ee
7 files changed
+14 -18

No files matched your search

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