mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-06 03:49:56 +08:00
fix: can not enable workspace if not sign in (#4265)
Co-authored-by: Alex Yang <himself65@outlook.com>
This commit is contained in:
@@ -6,11 +6,12 @@ import {
|
||||
getInviteInfoQuery,
|
||||
} from '@affine/graphql';
|
||||
import { fetcher } from '@affine/workspace/affine/gql';
|
||||
import { useAtom } from 'jotai';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import { type LoaderFunction, redirect, useLoaderData } from 'react-router-dom';
|
||||
|
||||
import { authAtom } from '../atoms';
|
||||
import { setOnceSignedInEventAtom } from '../atoms/event';
|
||||
import { useCurrentLoginStatus } from '../hooks/affine/use-current-login-status';
|
||||
import { RouteLogic, useNavigateHelper } from '../hooks/use-navigate-helper';
|
||||
import { useAppHelper } from '../hooks/use-workspaces';
|
||||
@@ -51,16 +52,14 @@ export const Component = () => {
|
||||
const { addCloudWorkspace } = useAppHelper();
|
||||
const { jumpToSubPath } = useNavigateHelper();
|
||||
|
||||
const [, setAuthAtom] = useAtom(authAtom);
|
||||
const setOnceSignedInEvent = useSetAtom(setOnceSignedInEventAtom);
|
||||
|
||||
const setAuthAtom = useSetAtom(authAtom);
|
||||
const { inviteInfo } = useLoaderData() as {
|
||||
inviteId: string;
|
||||
inviteInfo: GetInviteInfoQuery['getInviteInfo'];
|
||||
};
|
||||
|
||||
const loadWorkspaceAfterSignIn = useCallback(() => {
|
||||
addCloudWorkspace(inviteInfo.workspace.id);
|
||||
}, [addCloudWorkspace, inviteInfo.workspace.id]);
|
||||
|
||||
const openWorkspace = useCallback(() => {
|
||||
addCloudWorkspace(inviteInfo.workspace.id);
|
||||
jumpToSubPath(
|
||||
@@ -73,10 +72,7 @@ export const Component = () => {
|
||||
useEffect(() => {
|
||||
if (loginStatus === 'unauthenticated') {
|
||||
// We can not pass function to navigate state, so we need to save it in atom
|
||||
setAuthAtom(prev => ({
|
||||
...prev,
|
||||
onceSignedIn: loadWorkspaceAfterSignIn,
|
||||
}));
|
||||
setOnceSignedInEvent(openWorkspace);
|
||||
jumpToSignIn(RouteLogic.REPLACE, {
|
||||
state: {
|
||||
callbackURL: `/workspace/${inviteInfo.workspace.id}/all`,
|
||||
@@ -86,9 +82,10 @@ export const Component = () => {
|
||||
}, [
|
||||
inviteInfo.workspace.id,
|
||||
jumpToSignIn,
|
||||
loadWorkspaceAfterSignIn,
|
||||
loginStatus,
|
||||
openWorkspace,
|
||||
setAuthAtom,
|
||||
setOnceSignedInEvent,
|
||||
]);
|
||||
|
||||
if (loginStatus === 'authenticated') {
|
||||
|
||||
@@ -7,6 +7,7 @@ import { useLocation, useNavigate } from 'react-router-dom';
|
||||
import { authAtom } from '../atoms';
|
||||
import { AuthPanel } from '../components/affine/auth';
|
||||
import { useCurrentLoginStatus } from '../hooks/affine/use-current-login-status';
|
||||
import { RouteLogic, useNavigateHelper } from '../hooks/use-navigate-helper';
|
||||
|
||||
interface LocationState {
|
||||
state?: {
|
||||
@@ -14,36 +15,28 @@ interface LocationState {
|
||||
};
|
||||
}
|
||||
export const Component = () => {
|
||||
const [
|
||||
{ state, email = '', emailType = 'changePassword', onceSignedIn },
|
||||
setAuthAtom,
|
||||
] = useAtom(authAtom);
|
||||
const [{ state, email = '', emailType = 'changePassword' }, setAuthAtom] =
|
||||
useAtom(authAtom);
|
||||
const loginStatus = useCurrentLoginStatus();
|
||||
const location = useLocation() as LocationState;
|
||||
const navigate = useNavigate();
|
||||
const { jumpToIndex } = useNavigateHelper();
|
||||
|
||||
useEffect(() => {
|
||||
const afterSignedIn = async () => {
|
||||
if (loginStatus === 'authenticated') {
|
||||
if (onceSignedIn) {
|
||||
await onceSignedIn();
|
||||
setAuthAtom(prev => ({ ...prev, onceSignedIn: undefined }));
|
||||
}
|
||||
if (location.state?.callbackURL) {
|
||||
navigate(location.state.callbackURL, {
|
||||
replace: true,
|
||||
});
|
||||
}
|
||||
if (loginStatus === 'authenticated') {
|
||||
if (location.state?.callbackURL) {
|
||||
navigate(location.state.callbackURL, {
|
||||
replace: true,
|
||||
});
|
||||
} else {
|
||||
jumpToIndex(RouteLogic.REPLACE);
|
||||
}
|
||||
};
|
||||
afterSignedIn().catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
}, [
|
||||
jumpToIndex,
|
||||
location.state?.callbackURL,
|
||||
loginStatus,
|
||||
navigate,
|
||||
onceSignedIn,
|
||||
setAuthAtom,
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user