Fix inviter id undefined error (#72)
Co-authored-by: AceDataCloud <office@acedata.cloud>
This commit is contained in:
1 parent
e1a1be7833
commit
091a5312cf
3 files changed
+30
-2
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"type": "patch",
|
||||||
|
"comment": "fix for inviter id",
|
||||||
|
"packageName": "@acedatacloud/nexior",
|
||||||
|
"email": "office@acedata.cloud",
|
||||||
|
"dependentChangeType": "patch"
|
||||||
|
}
|
||||||
@@ -9,7 +9,6 @@ import { login as authLogin } from '@/utils';
|
|||||||
export const resetAll = ({ commit }: ActionContext<IRootState, IRootState>) => {
|
export const resetAll = ({ commit }: ActionContext<IRootState, IRootState>) => {
|
||||||
commit('resetToken');
|
commit('resetToken');
|
||||||
commit('resetUser');
|
commit('resetUser');
|
||||||
commit('resetSite');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const resetUser = ({ commit }: ActionContext<IRootState, IRootState>) => {
|
export const resetUser = ({ commit }: ActionContext<IRootState, IRootState>) => {
|
||||||
|
|||||||
+23
-1
@@ -1,11 +1,33 @@
|
|||||||
|
import store from '@/store';
|
||||||
import { getBaseUrlAuth, getBaseUrlHub } from './baseUrl';
|
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 }) => {
|
export const login = ({ redirect = '/', site = window.location.origin }: { redirect?: string; site?: string }) => {
|
||||||
const hubBaseUrl = getBaseUrlHub();
|
const hubBaseUrl = getBaseUrlHub();
|
||||||
const authBaseUrl = getBaseUrlAuth();
|
const authBaseUrl = getBaseUrlAuth();
|
||||||
|
const inviterId = getInviterId();
|
||||||
// callback url used to init access token and then redirect back of `redirect`
|
// callback url used to init access token and then redirect back of `redirect`
|
||||||
const callbackUrl = `${hubBaseUrl}/auth/callback?redirect=${redirect}`;
|
const callbackUrl = `${hubBaseUrl}/auth/callback?redirect=${redirect}`;
|
||||||
// redirect to auth service to get access token then redirect back
|
// 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;
|
window.location.href = targetUrl;
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user