diff --git a/packages/client/src/workspaces/contexts/ThothInterfaceProvider.tsx b/packages/client/src/workspaces/contexts/ThothInterfaceProvider.tsx index 47d265db7..5e6dc1c7a 100644 --- a/packages/client/src/workspaces/contexts/ThothInterfaceProvider.tsx +++ b/packages/client/src/workspaces/contexts/ThothInterfaceProvider.tsx @@ -12,18 +12,23 @@ import { usePubSub } from '../../contexts/PubSubProvider' import { useFetchFromImageCacheMutation } from '@/state/api/visualGenerationsApi' import { useGetSpellQuery, useRunSpellMutation } from '@/state/api/spells' import { useAuth } from '@/contexts/AuthProvider' +import { useDispatch } from 'react-redux' +import { closeTab } from '@/state/tabs' +import { useNavigate } from 'react-router' const Context = createContext(undefined!) export const useThothInterface = () => useContext(Context) const ThothInterfaceProvider = ({ children, tab }) => { + const dispatch = useDispatch() + const navigate = useNavigate() const { events, publish, subscribe } = usePubSub() const spellRef = useRef(null) const [fetchFromImageCache] = useFetchFromImageCacheMutation() const { user } = useAuth() const [_runSpell] = useRunSpellMutation() - const { data: _spell } = useGetSpellQuery( + const { data: _spell, isError: _isSpellError } = useGetSpellQuery( { spellId: tab.spellId, userId: user?.id as string, @@ -34,9 +39,16 @@ const ThothInterfaceProvider = ({ children, tab }) => { ) useEffect(() => { + console.log(); + + if (!_spell && _isSpellError) { + dispatch(closeTab(tab.id)) + navigate('/home') + return + } if (!_spell) return spellRef.current = _spell - }, [_spell]) + }, [_spell, _isSpellError]) const { $PLAYTEST_INPUT, diff --git a/packages/server/src/routes/spells/index.ts b/packages/server/src/routes/spells/index.ts index 6725e0c0b..842b69589 100644 --- a/packages/server/src/routes/spells/index.ts +++ b/packages/server/src/routes/spells/index.ts @@ -303,14 +303,7 @@ const getSpellHandler = async (ctx: Koa.Context) => { }) if (!spell) { - const newSpell = await creatorToolsDatabase.spells.create({ - userId: ctx.state.user?.id ?? ctx.query.userId, - name, - graph: { id: 'demo@0.1.0', nodes: {} }, - gameState: {}, - modules: [], - }) - ctx.body = newSpell + throw new Error('Spell not found') } else { let userId = ctx.state.user?.id ?? ctx.query.userId if (spell?.userId !== userId) throw new Error('spell not found')