feat: user login

This commit is contained in:
DiamondThree 2023-01-09 21:41:55 +08:00
parent 054e1f78e1
commit f6826d73fa
2 changed files with 21 additions and 2 deletions

View File

@ -15,6 +15,7 @@ import { toast } from '@/ui/toast';
import { WorkspaceAvatar } from '@/components/workspace-avatar';
import { useAppState } from '@/providers/app-state-provider';
import { useRouter } from 'next/router';
import { useUserHelper } from '@/hooks/use-user-helper';
interface WorkspaceModalProps {
open: boolean;
@ -24,7 +25,8 @@ interface WorkspaceModalProps {
export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => {
const [createWorkspaceOpen, setCreateWorkspaceOpen] = useState(false);
const { confirm } = useConfirm();
const { user, workspaceList, currentWorkspace } = useAppState();
const { workspaceList, currentWorkspace } = useAppState();
const { login, user } = useUserHelper();
const router = useRouter();
return (
<div>
@ -132,7 +134,7 @@ export const WorkspaceModal = ({ open, onClose }: WorkspaceModalProps) => {
{!user ? (
<Button
onClick={() => {
// login();
login();
toast('login success');
}}
>

View File

@ -0,0 +1,17 @@
import { useAppState } from '@/providers/app-state-provider';
import { User } from '@affine/datacenter';
import { useState } from 'react';
export const useUserHelper = () => {
const { dataCenter } = useAppState();
const [user, setUser] = useState<User | undefined>(undefined);
const login = async () => {
await dataCenter.login();
const user = await dataCenter.getUserInfo();
setUser(user);
};
return {
user,
login,
};
};