Skip to content

Commit

Permalink
Fix auth cookie persist path (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
崔庆才丨静觅 authored Jan 3, 2024
1 parent ca053b6 commit abbfc84
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix bug of perist cookie",
"packageName": "@zhishuyun/hub",
"email": "[email protected]",
"dependentChangeType": "patch"
}
3 changes: 0 additions & 3 deletions src/constants/env.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/constants/errorCode.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
1 change: 0 additions & 1 deletion src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './errorCode';
export * from './env';
export * from './endpoint';
12 changes: 1 addition & 11 deletions src/operators/instance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import router, { ROUTE_AUTH_LOGIN } from '@/router';
import store from '@/store';
import { getBaseUrlData } from '@/utils';
import axios, { AxiosInstance } from 'axios';
Expand All @@ -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}`;
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/auth/Callback.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}
}
Expand Down
16 changes: 10 additions & 6 deletions src/utils/initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '/'
});
}
};

0 comments on commit abbfc84

Please sign in to comment.