mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-06 11:59:51 +08:00
feat: login token state
This commit is contained in:
@@ -1,29 +1,7 @@
|
||||
import useSWR from 'swr';
|
||||
import type { SWRConfiguration } from 'swr';
|
||||
import { login, getUserByEmail } from './user';
|
||||
import type {
|
||||
LoginParams,
|
||||
LoginResponse,
|
||||
GetUserByEmailParams,
|
||||
User,
|
||||
} from './user';
|
||||
|
||||
export const LOGIN_SWR_KEY = 'user.token';
|
||||
export function useLogin(params: LoginParams, config?: SWRConfiguration) {
|
||||
const { data, error, isValidating, isLoading, mutate } =
|
||||
useSWR<LoginResponse>(
|
||||
[LOGIN_SWR_KEY, params],
|
||||
([_, params]) => login(params),
|
||||
config
|
||||
);
|
||||
|
||||
return {
|
||||
loading: isLoading,
|
||||
data,
|
||||
error,
|
||||
mutate,
|
||||
};
|
||||
}
|
||||
import { getUserByEmail } from './user';
|
||||
import type { GetUserByEmailParams, User } from './user';
|
||||
|
||||
export const GET_USER_BY_EMAIL_SWR_TOKEN = 'user.getUserByEmail';
|
||||
export function useGetUserByEmail(
|
||||
|
||||
@@ -1,37 +1,5 @@
|
||||
import { request } from '../request';
|
||||
|
||||
export interface ExchangeToken {
|
||||
type: 'Google';
|
||||
/**
|
||||
* Token from firebase.
|
||||
*/
|
||||
token: string;
|
||||
}
|
||||
|
||||
export interface RefreshToken {
|
||||
type: 'Refresh';
|
||||
token: string;
|
||||
}
|
||||
|
||||
export type LoginParams = ExchangeToken | RefreshToken;
|
||||
|
||||
export interface LoginResponse {
|
||||
/**
|
||||
* JWT, expires in a very short time
|
||||
*/
|
||||
token: string;
|
||||
/**
|
||||
* Refresh token
|
||||
*/
|
||||
refresh: string;
|
||||
}
|
||||
|
||||
export async function login(params: LoginParams): Promise<LoginResponse> {
|
||||
return request
|
||||
.post('/api/user/token', { json: params, headers: { token: undefined } })
|
||||
.json<LoginResponse>();
|
||||
}
|
||||
|
||||
export interface GetUserByEmailParams {
|
||||
email: string;
|
||||
workspaceId: string;
|
||||
|
||||
@@ -156,13 +156,6 @@ export async function downloadWorkspace(
|
||||
|
||||
export async function uploadBlob(params: { blob: Blob }): Promise<string> {
|
||||
return request.post('/api/blob', { body: params.blob }).text();
|
||||
|
||||
// const data = await request({
|
||||
// url: '/api/blob',
|
||||
// method: 'PUT',
|
||||
// data: params.blob,
|
||||
// });
|
||||
// return data.data;
|
||||
}
|
||||
|
||||
export async function getBlob(params: {
|
||||
|
||||
Reference in New Issue
Block a user