mirror of
https://github.com/colanode/colanode.git
synced 2025-12-28 16:06:37 +01:00
Fix login/register redirect flow
This commit is contained in:
@@ -120,6 +120,8 @@ export class EmailLoginMutationHandler
|
||||
return {
|
||||
output: {
|
||||
success: true,
|
||||
account: data.account,
|
||||
workspaces: data.workspaces,
|
||||
},
|
||||
changes: changedTables,
|
||||
};
|
||||
|
||||
@@ -121,6 +121,8 @@ export class EmailRegisterMutationHandler
|
||||
return {
|
||||
output: {
|
||||
success: true,
|
||||
account: data.account,
|
||||
workspaces: data.workspaces,
|
||||
},
|
||||
changes: changedTables,
|
||||
};
|
||||
|
||||
@@ -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' {
|
||||
|
||||
@@ -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' {
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user