You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailchat/shared/model/user.ts

89 lines
1.6 KiB
TypeScript

import { request } from '../api/request';
export interface UserBaseInfo {
_id: string;
email: string;
nickname: string;
discriminator: string;
avatar: string | null;
}
export interface UserLoginInfo extends UserBaseInfo {
token: string;
createdAt: string;
}
/**
* 邮箱登录
* @param email 邮箱
* @param password 密码
*/
export async function loginWithEmail(
email: string,
password: string
): Promise<UserLoginInfo> {
const { data } = await request.post('/api/user/login', {
email,
password,
});
return data;
}
/**
* 使用 Token 登录
* @param token JWT令牌
*/
export async function loginWithToken(token: string): Promise<UserLoginInfo> {
const { data } = await request.post('/api/user/resolveToken', {
token,
});
return data;
}
/**
* 邮箱注册账号
* @param email 邮箱
* @param password 密码
*/
export async function registerWithEmail(
email: string,
password: string
): Promise<UserLoginInfo> {
const { data } = await request.post('/api/user/register', {
email,
password,
});
return data;
}
/**
* 使用唯一标识名搜索用户
* @param uniqueName 唯一标识用户昵称: 用户昵称#0000
*/
export async function searchUserWithUniqueName(
uniqueName: string
): Promise<UserBaseInfo> {
const { data } = await request.post('/api/user/searchUserWithUniqueName', {
uniqueName,
});
return data;
}
/**
* 获取用户基本信息
* @param userId 用户ID
*/
export async function fetchUserInfo(userId: string): Promise<UserBaseInfo> {
const { data } = await request.get('/api/user/getUserInfo', {
params: {
userId,
},
});
return data;
}