Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inviter id undefined error #72

Merged
merged 2 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix for inviter id",
"packageName": "@acedatacloud/nexior",
"email": "office@acedata.cloud",
"dependentChangeType": "patch"
}
1 change: 0 additions & 1 deletion src/store/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { login as authLogin } from '@/utils';
export const resetAll = ({ commit }: ActionContext<IRootState, IRootState>) => {
commit('resetToken');
commit('resetUser');
commit('resetSite');
};

export const resetUser = ({ commit }: ActionContext<IRootState, IRootState>) => {
Expand Down
24 changes: 23 additions & 1 deletion src/utils/login.ts
Original file line number Diff line number Diff line change
@@ -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;
};
Loading