Open-source and local-first Slack and Notion alternative that puts you in control of your data
TypeScript chatchat-applicationcrdteditorelectronknowledge-baselocal-firstnotionnotion-alternativerealtime-collaborationself-hostedslacksqliteteam-collaborationwikiyjs
Fix login/register redirect flow
Hakan Shehu5e297f327a5e
diff --git a/desktop/src/main/handlers/mutations/email-login.ts b/desktop/src/main/handlers/mutations/email-login.tsindex 2c75dd91..d37ddcf1 100644--- a/desktop/src/main/handlers/mutations/email-login.ts+++ b/desktop/src/main/handlers/mutations/email-login.ts@@ -120,6 +120,8 @@ export class EmailLoginMutationHandlerreturn {output: {success: true,+ account: data.account,+ workspaces: data.workspaces,},changes: changedTables,};diff --git a/desktop/src/main/handlers/mutations/email-register.ts b/desktop/src/main/handlers/mutations/email-register.tsindex c6b77fde..04df61b4 100644--- a/desktop/src/main/handlers/mutations/email-register.ts+++ b/desktop/src/main/handlers/mutations/email-register.ts@@ -121,6 +121,8 @@ export class EmailRegisterMutationHandlerreturn {output: {success: true,+ account: data.account,+ workspaces: data.workspaces,},changes: changedTables,};diff --git a/desktop/src/operations/mutations/email-login.ts b/desktop/src/operations/mutations/email-login.tsindex c4ffb853..3a5d63a0 100644--- a/desktop/src/operations/mutations/email-login.ts+++ b/desktop/src/operations/mutations/email-login.ts@@ -1,3 +1,6 @@+import { Account } from '@/types/accounts';+import { WorkspaceOutput } from '@/types/workspaces';+export type EmailLoginMutationInput = {type: 'email_login';server: string;@@ -5,8 +8,18 @@ export type EmailLoginMutationInput = {password: string;};-export type EmailLoginMutationOutput = {- success: boolean;+export type EmailLoginMutationOutput =+ | EmailLoginMutationSuccessOutput+ | EmailLoginMutationErrorOutput;++export type EmailLoginMutationSuccessOutput = {+ success: true;+ account: Account;+ workspaces: WorkspaceOutput[];+};++export type EmailLoginMutationErrorOutput = {+ success: false;};declare module '@/operations/mutations' {diff --git a/desktop/src/operations/mutations/email-register.ts b/desktop/src/operations/mutations/email-register.tsindex 9851671c..c0e485b2 100644--- a/desktop/src/operations/mutations/email-register.ts+++ b/desktop/src/operations/mutations/email-register.ts@@ -1,3 +1,6 @@+import { Account } from '@/types/accounts';+import { WorkspaceOutput } from '@/types/workspaces';+export type EmailRegisterMutationInput = {type: 'email_register';server: string;@@ -6,8 +9,18 @@ export type EmailRegisterMutationInput = {password: string;};-export type EmailRegisterMutationOutput = {- success: boolean;+export type EmailRegisterMutationOutput =+ | EmailRegisterMutationSuccessOutput+ | EmailRegisterMutationErrorOutput;++export type EmailRegisterMutationSuccessOutput = {+ success: true;+ account: Account;+ workspaces: WorkspaceOutput[];+};++export type EmailRegisterMutationErrorOutput = {+ success: false;};declare module '@/operations/mutations' {diff --git a/desktop/src/renderer/components/accounts/email-login.tsx b/desktop/src/renderer/components/accounts/email-login.tsxindex e8133d40..d25b02d7 100644--- a/desktop/src/renderer/components/accounts/email-login.tsx+++ b/desktop/src/renderer/components/accounts/email-login.tsx@@ -46,8 +46,20 @@ export const EmailLogin = ({ server }: EmailLoginProps) => {password: values.password,server: server.domain,},- onSuccess() {- navigate('/');+ onSuccess(output) {+ if (output.success) {+ if (output.workspaces.length > 0) {+ navigate(`/${output.workspaces[0].id}`);+ } else {+ navigate('/create');+ }+ } else {+ toast({+ title: 'Failed to login',+ description: 'Invalid email or password.',+ variant: 'destructive',+ });+ }},onError() {toast({diff --git a/desktop/src/renderer/components/accounts/email-register.tsx b/desktop/src/renderer/components/accounts/email-register.tsxindex 3ec0307e..9656e207 100644--- a/desktop/src/renderer/components/accounts/email-register.tsx+++ b/desktop/src/renderer/components/accounts/email-register.tsx@@ -49,8 +49,20 @@ export const EmailRegister = ({ server }: EmailRegisterProps) => {password: values.password,server: server.domain,},- onSuccess() {- navigate('/');+ onSuccess(output) {+ if (output.success) {+ if (output.workspaces.length > 0) {+ navigate(`/${output.workspaces[0].id}`);+ } else {+ navigate('/create');+ }+ } else {+ toast({+ title: 'Failed to register',+ description: 'Email already in use.',+ variant: 'destructive',+ });+ }},onError() {toast({diff --git a/desktop/src/renderer/components/workspaces/workspace-create.tsx b/desktop/src/renderer/components/workspaces/workspace-create.tsxindex c4d303e3..7296f008 100644--- a/desktop/src/renderer/components/workspaces/workspace-create.tsx+++ b/desktop/src/renderer/components/workspaces/workspace-create.tsx@@ -12,7 +12,7 @@ export const WorkspaceCreate = () => {const { mutate, isPending } = useMutation();const handleCancel =- account.workspaces.length > 1 ? () => navigate('/') : undefined;+ account.workspaces.length > 0 ? () => navigate('/') : undefined;return (<div className="container flex flex-row justify-center">