mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-27 05:33:10 +03:00
feat: user login
This commit is contained in:
parent
054e1f78e1
commit
f6826d73fa
@ -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');
|
||||
}}
|
||||
>
|
||||
|
17
packages/app/src/hooks/use-user-helper.ts
Normal file
17
packages/app/src/hooks/use-user-helper.ts
Normal 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,
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue
Block a user