diff --git a/change/@acedatacloud-nexior-d045ef82-e913-4c29-93d9-0a3a1c8ccde1.json b/change/@acedatacloud-nexior-d045ef82-e913-4c29-93d9-0a3a1c8ccde1.json new file mode 100644 index 00000000..b874952a --- /dev/null +++ b/change/@acedatacloud-nexior-d045ef82-e913-4c29-93d9-0a3a1c8ccde1.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "fix for inviter id", + "packageName": "@acedatacloud/nexior", + "email": "office@acedata.cloud", + "dependentChangeType": "patch" +} diff --git a/src/store/common/actions.ts b/src/store/common/actions.ts index 01e8c504..b025f229 100644 --- a/src/store/common/actions.ts +++ b/src/store/common/actions.ts @@ -9,7 +9,6 @@ import { login as authLogin } from '@/utils'; export const resetAll = ({ commit }: ActionContext) => { commit('resetToken'); commit('resetUser'); - commit('resetSite'); }; export const resetUser = ({ commit }: ActionContext) => { diff --git a/src/utils/login.ts b/src/utils/login.ts index 4e02cd93..0f47e334 100644 --- a/src/utils/login.ts +++ b/src/utils/login.ts @@ -1,11 +1,33 @@ +import store from '@/store'; import { getBaseUrlAuth, getBaseUrlHub } from './baseUrl'; +import { getCookie } from 'typescript-cookie'; + +export const getInviterId = () => { + // if forceInviterId is set, then use forceInviterId + if (store?.state?.site?.distribution?.force_inviter_id) { + return store?.state?.site?.distribution?.force_inviter_id; + } + // parse the query string and set to cookies + const query = new URLSearchParams(window.location.search); + // Otherwise, use the inviter_id in the url, then use the inviter_id in the cookie, and finally use the default inviter_id + const result = + query.get('inviter_id') || getCookie('INVITER_ID') || store?.state?.site?.distribution?.default_inviter_id; + return result; +}; export const login = ({ redirect = '/', site = window.location.origin }: { redirect?: string; site?: string }) => { const hubBaseUrl = getBaseUrlHub(); const authBaseUrl = getBaseUrlAuth(); + const inviterId = getInviterId(); // callback url used to init access token and then redirect back of `redirect` const callbackUrl = `${hubBaseUrl}/auth/callback?redirect=${redirect}`; // redirect to auth service to get access token then redirect back - const targetUrl = `${authBaseUrl}/auth/login?redirect=${callbackUrl}&site=${site}`; + const targetBaseUrl = `${authBaseUrl}/auth/login`; + const targetQuery = { + site, + ...(inviterId ? { inviter_id: inviterId } : {}), + ...(callbackUrl ? { redirect: callbackUrl } : {}) + }; + const targetUrl = `${targetBaseUrl}?${new URLSearchParams(targetQuery).toString()}`; window.location.href = targetUrl; };