Add fingerprint tracker (#166)
Co-authored-by: Germey <germey@acedata.cloud>
This commit is contained in:
1 parent
cacab7efa3
commit
fa28d9a3aa
13 files changed
+110
-8
No files matched your search
+3
-1
@@ -20,7 +20,8 @@ import {
|
||||
initializeTitle,
|
||||
initializeCurrency,
|
||||
initializeExchangeRate,
|
||||
initializeRedirect
|
||||
initializeRedirect,
|
||||
initializeFingerprint
|
||||
} from './utils/initializer';
|
||||
|
||||
const main = async () => {
|
||||
@@ -38,6 +39,7 @@ const main = async () => {
|
||||
initializeDescription();
|
||||
initializeKeywords();
|
||||
initializeFavicon();
|
||||
initializeFingerprint();
|
||||
|
||||
const app = createApp(App);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import store from '@/store';
|
||||
import { getBaseUrlPlatform } from '@/utils';
|
||||
import axios, { AxiosInstance } from 'axios';
|
||||
import qs from 'qs';
|
||||
import { getCookie } from 'typescript-cookie';
|
||||
|
||||
const httpClient: AxiosInstance = axios.create({
|
||||
baseURL: `${getBaseUrlPlatform()}/api/v1`,
|
||||
@@ -16,9 +17,23 @@ const httpClient: AxiosInstance = axios.create({
|
||||
|
||||
httpClient.interceptors.request.use((config) => {
|
||||
const accessToken = store.getters.token?.access;
|
||||
const userId = store.getters.user?.id;
|
||||
const fingerprint = store.getters.fingerprint;
|
||||
const locale = getCookie('LOCALE');
|
||||
console.debug('userId', userId);
|
||||
console.debug('fingerprint', fingerprint);
|
||||
if (accessToken) {
|
||||
config.headers['Authorization'] = `Bearer ${accessToken}`;
|
||||
}
|
||||
if (locale) {
|
||||
config.headers['accept-language'] = locale;
|
||||
}
|
||||
if (fingerprint) {
|
||||
config.headers['x-fingerprint'] = fingerprint;
|
||||
}
|
||||
if (userId) {
|
||||
config.headers['x-user-id'] = userId;
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { ActionContext } from 'vuex';
|
||||
import { IRootState } from '../common/models';
|
||||
import { IRootState } from './models';
|
||||
import { userOperator, oauthOperator, siteOperator, exchangeOperator } from '@/operators';
|
||||
import { IToken, IUser } from '@/models';
|
||||
import { getSiteOrigin } from '@/utils/site';
|
||||
import { loginRedirect } from '@/utils';
|
||||
import { SURFACE_ANDROID, SURFACE_IOS } from '@/constants';
|
||||
import FingerprintJS from '@fingerprintjs/fingerprintjs';
|
||||
|
||||
export const resetAll = ({ commit }: ActionContext<IRootState, IRootState>) => {
|
||||
commit('resetToken');
|
||||
@@ -39,6 +40,10 @@ export const setExchange = ({ commit }: ActionContext<IRootState, IRootState>, p
|
||||
commit('setExchange', payload);
|
||||
};
|
||||
|
||||
export const setFingerprint = ({ commit }: ActionContext<IRootState, IRootState>, payload: any) => {
|
||||
commit('setFingerprint', payload);
|
||||
};
|
||||
|
||||
export const getUser = async ({ commit }: ActionContext<IRootState, IRootState>): Promise<IUser> => {
|
||||
console.debug('start to get user');
|
||||
try {
|
||||
@@ -52,6 +57,15 @@ export const getUser = async ({ commit }: ActionContext<IRootState, IRootState>)
|
||||
}
|
||||
};
|
||||
|
||||
export const getFingerprint = async ({ commit }: ActionContext<IRootState, IRootState>) => {
|
||||
const fp = await FingerprintJS.load();
|
||||
const result = await fp.get();
|
||||
const visitorId = result.visitorId;
|
||||
console.debug('visitorId', visitorId);
|
||||
commit('setFingerprint', visitorId);
|
||||
return visitorId;
|
||||
};
|
||||
|
||||
export const getToken = async ({ commit }: ActionContext<IRootState, IRootState>, code: string): Promise<IToken> => {
|
||||
console.debug('start to get token using code', code);
|
||||
try {
|
||||
@@ -155,8 +169,10 @@ export default {
|
||||
resetUser,
|
||||
resetSite,
|
||||
setToken,
|
||||
setFingerprint,
|
||||
setCurrency,
|
||||
setUser,
|
||||
getFingerprint,
|
||||
getExchangeRate,
|
||||
getToken,
|
||||
getUser,
|
||||
|
||||
@@ -20,10 +20,15 @@ export const site = (state: IRootState): any => {
|
||||
return state.site;
|
||||
};
|
||||
|
||||
export const fingerprint = (state: IRootState): any => {
|
||||
return state.fingerprint;
|
||||
};
|
||||
|
||||
export default {
|
||||
authenticated,
|
||||
user,
|
||||
token,
|
||||
site,
|
||||
fingerprint,
|
||||
setting
|
||||
};
|
||||
@@ -15,6 +15,7 @@ export interface ICommonState {
|
||||
setting?: ISetting;
|
||||
site?: ISite;
|
||||
currency: string;
|
||||
fingerprint?: string;
|
||||
auth: {
|
||||
flow: 'popup' | 'redirect';
|
||||
visible: boolean;
|
||||
|
||||
@@ -22,6 +22,10 @@ export const setAuth = (state: IRootState, payload: any): void => {
|
||||
};
|
||||
};
|
||||
|
||||
export const setFingerprint = (state: IRootState, payload: any): void => {
|
||||
state.fingerprint = payload;
|
||||
};
|
||||
|
||||
export const resetToken = (state: IRootState): void => {
|
||||
state.token = {};
|
||||
};
|
||||
@@ -59,6 +63,7 @@ export default {
|
||||
setCurrency,
|
||||
setExchange,
|
||||
resetUser,
|
||||
setFingerprint,
|
||||
setToken,
|
||||
resetToken,
|
||||
resetSite
|
||||
|
||||
@@ -1 +1 @@
|
||||
export default ['user', 'token', 'setting', 'locale', 'dark', 'site', 'currency', 'exchange'];
|
||||
export default ['user', 'token', 'setting', 'locale', 'dark', 'site', 'currency', 'exchange', 'fingerprint'];
|
||||
@@ -5,9 +5,11 @@ import chatdocState from '../chatdoc/state';
|
||||
import qrartState from '../qrart/state';
|
||||
import lumaState from '../luma/state';
|
||||
import sunoState from '../suno/state';
|
||||
import headshotsState from '../headshots/state';
|
||||
|
||||
export default (): IRootState => {
|
||||
return {
|
||||
fingerprint: undefined,
|
||||
currency: 'usd',
|
||||
exchange: undefined,
|
||||
user: {},
|
||||
@@ -27,6 +29,7 @@ export default (): IRootState => {
|
||||
midjourney: midjourneyState(),
|
||||
qrart: qrartState(),
|
||||
luma: lumaState(),
|
||||
suno: sunoState()
|
||||
suno: sunoState(),
|
||||
headshots: headshotsState()
|
||||
};
|
||||
};
|
||||
@@ -214,3 +214,7 @@ export const initializeRedirect = async () => {
|
||||
window.location.href = newUrl;
|
||||
}
|
||||
};
|
||||
|
||||
export const initializeFingerprint = async () => {
|
||||
await store.dispatch('getFingerprint');
|
||||
};
|
||||
Reference in new issue
Block a user