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
|
||||
};
|
||||
@@ -16,14 +16,9 @@ export const setting = (state: IRootState): any => {
|
||||
return state.setting;
|
||||
};
|
||||
|
||||
export const applications = (state: IRootState): any => {
|
||||
return state.applications;
|
||||
};
|
||||
|
||||
export default {
|
||||
authenticated,
|
||||
user,
|
||||
token,
|
||||
setting,
|
||||
applications
|
||||
setting
|
||||
};
|
||||
@@ -11,6 +11,7 @@ export enum Status {
|
||||
export interface IToken {
|
||||
access?: string;
|
||||
refresh?: string;
|
||||
expiration?: number;
|
||||
}
|
||||
|
||||
export interface ISetting {
|
||||
@@ -22,7 +23,6 @@ export interface ICommonState {
|
||||
token: IToken;
|
||||
user: IUser;
|
||||
setting: ISetting;
|
||||
applications: IApplication[] | undefined;
|
||||
}
|
||||
|
||||
export interface IRootState extends ICommonState {
|
||||
|
||||
@@ -26,14 +26,9 @@ export const setSetting = (state: IRootState, payload: any): void => {
|
||||
};
|
||||
};
|
||||
|
||||
export const setApplications = (state: IRootState, payload: any): void => {
|
||||
state.applications = payload;
|
||||
};
|
||||
|
||||
export default {
|
||||
setUser,
|
||||
setToken,
|
||||
resetToken,
|
||||
setSetting,
|
||||
setApplications
|
||||
setSetting
|
||||
};
|
||||
@@ -6,12 +6,12 @@ export default (): IRootState => {
|
||||
user: {},
|
||||
token: {
|
||||
access: undefined,
|
||||
refresh: undefined
|
||||
refresh: undefined,
|
||||
expiration: undefined
|
||||
},
|
||||
setting: {
|
||||
endpoint: ENDPOINT,
|
||||
stream: false
|
||||
},
|
||||
applications: undefined
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user