Optimize the auth flow (#68)

Co-authored-by: AceDataCloud <office@acedata.cloud>
This commit is contained in:
GermeyandAceDataCloud authored and GitHub committed 2024-07-03 17:17:11 +00:00
1 parent 033cbc082c
commit 85aef535f6
23 files changed
+215 -245

No files matched your search

+26
View File
@@ -3,6 +3,7 @@ import favicon from '@/assets/images/favicon.ico';
import { getLocale } from '@/i18n';
import store from '@/store';
import { log } from './log';
import { IToken } from '@/models';
export const getDomain = () => {
const host = window.location.hostname;
@@ -140,3 +141,28 @@ export const initializeSite = async () => {
await store.dispatch('initializeSite');
}
};
/**
* Initialize token by code
*/
export const initializeToken = async () => {
const query = new URLSearchParams(window.location.search);
const code = query.get('code');
if (code) {
const token = await store.dispatch('getToken', code);
console.debug('get token', token);
}
};
/**
* Initialize user by token
*/
export const initializeUser = async () => {
const token = store.state.token as IToken;
if (!token?.access) {
console.debug('no access token, skip get user');
return;
}
const user = await store.dispatch('getUser');
console.debug('get user', user);
};