refactor chat
This commit is contained in:
1 parent
565b367c59
commit
cd5dbaa264
20 files changed
+192
-230
No files matched your search
@@ -1,6 +1,8 @@
|
||||
import { ActionContext } from 'vuex';
|
||||
import { IRootState, IToken } from '../common/models';
|
||||
import { IApplication, IUser } from '@/operators';
|
||||
import { IApplication, IUser, userOperator } from '@/operators';
|
||||
import { log } from '@/utils/log';
|
||||
import { oauthOperator } from '@/operators/auth/operator';
|
||||
|
||||
export const resetToken = ({ commit }: ActionContext<IRootState, IRootState>) => {
|
||||
commit('resetToken');
|
||||
@@ -14,13 +16,33 @@ export const setUser = ({ commit }: ActionContext<IRootState, IRootState>, paylo
|
||||
commit('setUser', payload);
|
||||
};
|
||||
|
||||
export const setApplications = ({ commit }: ActionContext<IRootState, IRootState>, payload: IApplication[]) => {
|
||||
commit('setApplications', payload);
|
||||
export const getUser = async ({ commit }: ActionContext<IRootState, IRootState>): Promise<IUser> => {
|
||||
log(getUser, 'start to get user');
|
||||
const { data: user } = await userOperator.getMe();
|
||||
commit('setUser', user);
|
||||
log(getUser, 'get user success', user);
|
||||
return user;
|
||||
};
|
||||
|
||||
export const getToken = async ({ commit }: ActionContext<IRootState, IRootState>, code: string): Promise<IToken> => {
|
||||
log(getToken, 'start to get token using code', code);
|
||||
const { data } = await oauthOperator.token({
|
||||
code
|
||||
});
|
||||
const token = {
|
||||
access: data.access_token,
|
||||
refresh: data.refresh_token,
|
||||
expiration: data.expires_in
|
||||
};
|
||||
commit('setToken', token);
|
||||
log(getToken, 'get token success', data);
|
||||
return token;
|
||||
};
|
||||
|
||||
export default {
|
||||
resetToken,
|
||||
setToken,
|
||||
setUser,
|
||||
setApplications
|
||||
getToken,
|
||||
getUser
|
||||
};
|
||||
Reference in new issue
Block a user