mirror of
https://github.com/docmost/docmost.git
synced 2025-11-12 16:42:37 +10:00
cleanups
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
import { Navigate, Route, Routes } from "react-router-dom";
|
||||
import { Welcome } from "@/pages/welcome";
|
||||
import SignUpPage from "@/pages/auth/signup";
|
||||
import SetupWorkspace from "@/pages/auth/setup-workspace.tsx";
|
||||
import LoginPage from "@/pages/auth/login";
|
||||
import Home from "@/pages/dashboard/home";
|
||||
import Page from "@/pages/page/page";
|
||||
@ -20,11 +19,11 @@ import { io } from "socket.io-client";
|
||||
import { authTokensAtom } from "@/features/auth/atoms/auth-tokens-atom.ts";
|
||||
import { SOCKET_URL } from "@/features/websocket/types";
|
||||
import AccountPreferences from "@/pages/settings/account/account-preferences.tsx";
|
||||
import { InviteSignUpForm } from "@/features/auth/components/invite-sign-up-form.tsx";
|
||||
import SpaceHome from "@/pages/space/space-home.tsx";
|
||||
import PageRedirect from "@/pages/page/page-redirect.tsx";
|
||||
import Layout from "@/components/layouts/global/layout.tsx";
|
||||
import { ErrorBoundary } from "react-error-boundary";
|
||||
import InviteSignup from "@/pages/auth/invite-signup.tsx";
|
||||
|
||||
export default function App() {
|
||||
const [, setSocket] = useAtom(socketAtom);
|
||||
@ -62,8 +61,8 @@ export default function App() {
|
||||
<Routes>
|
||||
<Route index element={<Navigate to="/home" />} />
|
||||
<Route path={"/login"} element={<LoginPage />} />
|
||||
<Route path={"/signup"} element={<SignUpPage />} />
|
||||
<Route path={"/invites/:invitationId"} element={<InviteSignUpForm />} />
|
||||
<Route path={"/installation/setup"} element={<SetupWorkspace />} />
|
||||
<Route path={"/invites/:invitationId"} element={<InviteSignup />} />
|
||||
|
||||
<Route path={"/p/:pageSlug"} element={<PageRedirect />} />
|
||||
|
||||
|
||||
@ -29,7 +29,9 @@ export function InviteSignUpForm() {
|
||||
const params = useParams();
|
||||
const [searchParams] = useSearchParams();
|
||||
|
||||
const { data: invitation } = useGetInvitationQuery(params?.invitationId);
|
||||
const { data: invitation, isError } = useGetInvitationQuery(
|
||||
params?.invitationId,
|
||||
);
|
||||
const { invitationSignup, isLoading } = useAuth();
|
||||
useRedirectIfAuthenticated();
|
||||
|
||||
@ -52,6 +54,10 @@ export function InviteSignUpForm() {
|
||||
});
|
||||
}
|
||||
|
||||
if (isError) {
|
||||
return <div>invalid invitation link</div>;
|
||||
}
|
||||
|
||||
if (!invitation) {
|
||||
return <div></div>;
|
||||
}
|
||||
|
||||
@ -71,13 +71,6 @@ export function LoginForm() {
|
||||
Sign In
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
<Text c="dimmed" size="sm" ta="center" mt="sm">
|
||||
Don't have an account yet?{" "}
|
||||
<Anchor size="sm" component={Link} to="/signup">
|
||||
Create account
|
||||
</Anchor>
|
||||
</Text>
|
||||
</Box>
|
||||
</Container>
|
||||
);
|
||||
|
||||
@ -1,83 +0,0 @@
|
||||
import * as React from "react";
|
||||
import * as z from "zod";
|
||||
|
||||
import { useForm, zodResolver } from "@mantine/form";
|
||||
import {
|
||||
Container,
|
||||
Title,
|
||||
Anchor,
|
||||
TextInput,
|
||||
Button,
|
||||
Text,
|
||||
PasswordInput,
|
||||
Box,
|
||||
} from "@mantine/core";
|
||||
import { Link } from "react-router-dom";
|
||||
import { IRegister } from "@/features/auth/types/auth.types";
|
||||
import useAuth from "@/features/auth/hooks/use-auth";
|
||||
import classes from "@/features/auth/components/auth.module.css";
|
||||
import { useRedirectIfAuthenticated } from "@/features/auth/hooks/use-redirect-if-authenticated.ts";
|
||||
|
||||
const formSchema = z.object({
|
||||
email: z
|
||||
.string()
|
||||
.min(1, { message: "email is required" })
|
||||
.email({ message: "Invalid email address" }),
|
||||
password: z.string().min(1, { message: "Password is required" }),
|
||||
});
|
||||
|
||||
export function SignUpForm() {
|
||||
const { signUp, isLoading } = useAuth();
|
||||
useRedirectIfAuthenticated();
|
||||
|
||||
const form = useForm<IRegister>({
|
||||
validate: zodResolver(formSchema),
|
||||
initialValues: {
|
||||
email: "",
|
||||
password: "",
|
||||
},
|
||||
});
|
||||
|
||||
async function onSubmit(data: IRegister) {
|
||||
await signUp(data);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container size={420} my={40} className={classes.container}>
|
||||
<Box p="xl" mt={200}>
|
||||
<Title order={2} ta="center" fw={500} mb="md">
|
||||
Create an account
|
||||
</Title>
|
||||
|
||||
<form onSubmit={form.onSubmit(onSubmit)}>
|
||||
<TextInput
|
||||
id="email"
|
||||
type="email"
|
||||
label="Email"
|
||||
placeholder="email@example.com"
|
||||
variant="filled"
|
||||
{...form.getInputProps("email")}
|
||||
/>
|
||||
|
||||
<PasswordInput
|
||||
label="Password"
|
||||
placeholder="Your password"
|
||||
variant="filled"
|
||||
mt="md"
|
||||
{...form.getInputProps("password")}
|
||||
/>
|
||||
<Button type="submit" fullWidth mt="xl" loading={isLoading}>
|
||||
Sign Up
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
<Text c="dimmed" size="sm" ta="center" mt="sm">
|
||||
Already have an account?{" "}
|
||||
<Anchor size="sm" component={Link} to="/login">
|
||||
Login
|
||||
</Anchor>
|
||||
</Text>
|
||||
</Box>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
@ -1,9 +1,5 @@
|
||||
import { useState } from "react";
|
||||
import {
|
||||
login,
|
||||
register,
|
||||
setupWorkspace,
|
||||
} from "@/features/auth/services/auth-service";
|
||||
import { login, setupWorkspace } from "@/features/auth/services/auth-service";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useAtom } from "jotai";
|
||||
import { authTokensAtom } from "@/features/auth/atoms/auth-tokens-atom";
|
||||
@ -46,25 +42,6 @@ export default function useAuth() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleSignUp = async (data: IRegister) => {
|
||||
setIsLoading(true);
|
||||
|
||||
try {
|
||||
const res = await register(data);
|
||||
setIsLoading(false);
|
||||
|
||||
setAuthToken(res.tokens);
|
||||
|
||||
navigate(APP_ROUTE.HOME);
|
||||
} catch (err) {
|
||||
setIsLoading(false);
|
||||
notifications.show({
|
||||
message: err.response?.data.message,
|
||||
color: "red",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleInvitationSignUp = async (data: IAcceptInvite) => {
|
||||
setIsLoading(true);
|
||||
|
||||
@ -135,7 +112,6 @@ export default function useAuth() {
|
||||
|
||||
return {
|
||||
signIn: handleSignIn,
|
||||
signUp: handleSignUp,
|
||||
invitationSignup: handleInvitationSignUp,
|
||||
setupWorkspace: handleSetupWorkspace,
|
||||
isAuthenticated: handleIsAuthenticated,
|
||||
|
||||
@ -12,10 +12,11 @@ export async function login(data: ILogin): Promise<ITokenResponse> {
|
||||
return req.data;
|
||||
}
|
||||
|
||||
/*
|
||||
export async function register(data: IRegister): Promise<ITokenResponse> {
|
||||
const req = await api.post<ITokenResponse>("/auth/register", data);
|
||||
return req.data;
|
||||
}
|
||||
}*/
|
||||
|
||||
export async function changePassword(
|
||||
data: IChangePassword,
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import api from "@/lib/api-client";
|
||||
import { ICurrentUser, IUser } from "@/features/user/types/user.types";
|
||||
import { IAttachment } from "@/lib/types.ts";
|
||||
|
||||
export async function getMyInfo(): Promise<ICurrentUser> {
|
||||
const req = await api.post<ICurrentUser>("/users/me");
|
||||
@ -22,6 +21,5 @@ export async function uploadAvatar(file: File): Promise<any> {
|
||||
"Content-Type": "multipart/form-data",
|
||||
},
|
||||
});
|
||||
console.log(req);
|
||||
return req;
|
||||
}
|
||||
|
||||
13
apps/client/src/pages/auth/invite-signup.tsx
Normal file
13
apps/client/src/pages/auth/invite-signup.tsx
Normal file
@ -0,0 +1,13 @@
|
||||
import { Helmet } from "react-helmet-async";
|
||||
import { InviteSignUpForm } from "@/features/auth/components/invite-sign-up-form.tsx";
|
||||
|
||||
export default function InviteSignup() {
|
||||
return (
|
||||
<>
|
||||
<Helmet>
|
||||
<title>Invitation signup</title>
|
||||
</Helmet>
|
||||
<InviteSignUpForm />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
interface AuthLayoutProps {
|
||||
children: React.ReactNode
|
||||
}
|
||||
|
||||
export default function AuthLayout({ children }: AuthLayoutProps) {
|
||||
return <div>{children}</div>
|
||||
}
|
||||
@ -1,10 +1,10 @@
|
||||
import { SignUpForm } from "@/features/auth/components/sign-up-form";
|
||||
import { useWorkspacePublicDataQuery } from "@/features/workspace/queries/workspace-query.ts";
|
||||
import { SetupWorkspaceForm } from "@/features/auth/components/setup-workspace-form.tsx";
|
||||
import { Helmet } from "react-helmet-async";
|
||||
import React from "react";
|
||||
import React, { useEffect } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
export default function SignUpPage() {
|
||||
export default function SetupWorkspace() {
|
||||
const {
|
||||
data: workspace,
|
||||
isLoading,
|
||||
@ -12,6 +12,14 @@ export default function SignUpPage() {
|
||||
error,
|
||||
} = useWorkspacePublicDataQuery();
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLoading && !isError && workspace) {
|
||||
navigate("/");
|
||||
}
|
||||
}, [isLoading, isError, workspace]);
|
||||
|
||||
if (isLoading) {
|
||||
return <div></div>;
|
||||
}
|
||||
@ -31,12 +39,5 @@ export default function SignUpPage() {
|
||||
);
|
||||
}
|
||||
|
||||
return workspace ? (
|
||||
<>
|
||||
<Helmet>
|
||||
<title>Signup</title>
|
||||
</Helmet>
|
||||
<SignUpForm />
|
||||
</>
|
||||
) : null;
|
||||
return null;
|
||||
}
|
||||
@ -33,11 +33,12 @@ export class AuthController {
|
||||
return this.authService.login(loginInput, req.raw.workspaceId);
|
||||
}
|
||||
|
||||
@HttpCode(HttpStatus.OK)
|
||||
/* @HttpCode(HttpStatus.OK)
|
||||
@Post('register')
|
||||
async register(@Req() req, @Body() createUserDto: CreateUserDto) {
|
||||
return this.authService.register(createUserDto, req.raw.workspaceId);
|
||||
}
|
||||
*/
|
||||
|
||||
@UseGuards(SetupGuard)
|
||||
@HttpCode(HttpStatus.OK)
|
||||
|
||||
@ -78,7 +78,11 @@ export class SignupService {
|
||||
// create user
|
||||
|
||||
const user = await this.userRepo.insertUser(
|
||||
{ ...createAdminUserDto, role: UserRole.OWNER },
|
||||
{
|
||||
...createAdminUserDto,
|
||||
role: UserRole.OWNER,
|
||||
emailVerifiedAt: new Date(),
|
||||
},
|
||||
trx,
|
||||
);
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ import { GroupUserRepo } from '@docmost/db/repos/group/group-user.repo';
|
||||
import InvitationAcceptedEmail from '@docmost/transactional/emails/invitation-accepted-email';
|
||||
import { EnvironmentService } from '../../../integrations/environment/environment.service';
|
||||
import { TokenService } from '../../auth/services/token.service';
|
||||
import { nanoIdGen } from '../../../common/helpers/nanoid.utils';
|
||||
import { nanoIdGen } from '../../../common/helpers';
|
||||
import { PaginationOptions } from '@docmost/db/pagination/pagination-options';
|
||||
import { executeWithPagination } from '@docmost/db/pagination/pagination';
|
||||
import { TokensDto } from '../../auth/dto/tokens.dto';
|
||||
@ -179,6 +179,7 @@ export class WorkspaceInvitationService {
|
||||
role: invitation.role,
|
||||
lastLoginAt: new Date(),
|
||||
invitedById: invitation.invitedById,
|
||||
emailVerifiedAt: new Date(),
|
||||
})
|
||||
.returningAll()
|
||||
.executeTakeFirst();
|
||||
|
||||
@ -2,17 +2,22 @@ import { MailDriver } from './interfaces/mail-driver.interface';
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { MailMessage } from '../interfaces/mail.message';
|
||||
import { mailLogName } from '../mail.utils';
|
||||
import * as process from 'node:process';
|
||||
|
||||
export class LogDriver implements MailDriver {
|
||||
private readonly logger = new Logger(mailLogName(LogDriver.name));
|
||||
|
||||
async sendMail(message: MailMessage): Promise<void> {
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
return;
|
||||
}
|
||||
|
||||
const mailLog = {
|
||||
to: message.to,
|
||||
subject: message.subject,
|
||||
text: message.text,
|
||||
};
|
||||
|
||||
this.logger.log(`Logged mail: ${JSON.stringify(mailLog)}`);
|
||||
this.logger.log(`Logged email: ${JSON.stringify(mailLog)}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user