mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-15 20:25:23 +02:00
Merge pull request #605 from Dokploy/feat/add-email-verification
Feat/add email verification
This commit is contained in:
3
.github/workflows/deploy.yml
vendored
3
.github/workflows/deploy.yml
vendored
@@ -74,7 +74,8 @@ jobs:
|
|||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
build-args: |
|
build-args: |
|
||||||
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=${{ github.ref_name == 'main' && 'pk_live_51QAm7bF3cxQuHeOzMpfNfJIch6oLif8rS32pRE392CdTbBf0MYBdbapAxarQGspqJBWT2nVOxu8e6ZHrHB4NhVHG008DE2A90d' || 'pk_test_51QAm7bF3cxQuHeOz0xg04o9teeyTbbNHQPJ5Tr98MlTEan9MzewT3gwh0jSWBNvrRWZ5vASoBgxUSF4gPWsJwATk00Ir2JZ0S1' }}
|
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=${{ github.ref_name == 'main' && 'pk_live_51QAm7bF3cxQuHeOzMpfNfJIch6oLif8rS32pRE392CdTbBf0MYBdbapAxarQGspqJBWT2nVOxu8e6ZHrHB4NhVHG008DE2A90d' || 'pk_test_51QAm7bF3cxQuHeOz0xg04o9teeyTbbNHQPJ5Tr98MlTEan9MzewT3gwh0jSWBNvrRWZ5vASoBgxUSF4gPWsJwATk00Ir2JZ0S1' }}
|
||||||
|
NEXT_PUBLIC_UMAMI_HOST="https://umami.dokploy.com/script.js"
|
||||||
|
NEXT_PUBLIC_UMAMI_WEBSITE_ID="ef083745-e111-4bac-9fe6-c549807adefe"
|
||||||
build-and-push-schedule-image:
|
build-and-push-schedule-image:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,15 @@ RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm --filter=@dokploy/server
|
|||||||
|
|
||||||
|
|
||||||
# Deploy only the dokploy app
|
# Deploy only the dokploy app
|
||||||
|
ARG NEXT_PUBLIC_UMAMI_HOST
|
||||||
|
ENV NEXT_PUBLIC_UMAMI_HOST=$NEXT_PUBLIC_UMAMI_HOST
|
||||||
|
|
||||||
|
ARG NEXT_PUBLIC_UMAMI_WEBSITE_ID
|
||||||
|
ENV NEXT_PUBLIC_UMAMI_WEBSITE_ID=$NEXT_PUBLIC_UMAMI_WEBSITE_ID
|
||||||
|
|
||||||
ARG NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
|
ARG NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
|
||||||
ENV NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=$NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
|
ENV NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=$NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
RUN pnpm --filter=@dokploy/server build
|
RUN pnpm --filter=@dokploy/server build
|
||||||
RUN pnpm --filter=./apps/dokploy run build
|
RUN pnpm --filter=./apps/dokploy run build
|
||||||
|
|||||||
@@ -63,6 +63,13 @@ export default function Layout({
|
|||||||
className={inter.className}
|
className={inter.className}
|
||||||
suppressHydrationWarning
|
suppressHydrationWarning
|
||||||
>
|
>
|
||||||
|
<head>
|
||||||
|
<script
|
||||||
|
defer
|
||||||
|
src="https://umami.dokploy.com/script.js"
|
||||||
|
data-website-id="6ad2aa56-6d38-4f39-97a8-1a8fcdda8d51"
|
||||||
|
/>
|
||||||
|
</head>
|
||||||
<GoogleAnalytics />
|
<GoogleAnalytics />
|
||||||
<body>
|
<body>
|
||||||
<I18nProvider
|
<I18nProvider
|
||||||
|
|||||||
@@ -6,7 +6,14 @@ import { cn } from "@/lib/utils";
|
|||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
import { loadStripe } from "@stripe/stripe-js";
|
import { loadStripe } from "@stripe/stripe-js";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { AlertTriangle, CheckIcon, MinusIcon, PlusIcon } from "lucide-react";
|
import {
|
||||||
|
AlertTriangle,
|
||||||
|
CheckIcon,
|
||||||
|
Loader2,
|
||||||
|
MinusIcon,
|
||||||
|
PlusIcon,
|
||||||
|
} from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
|
|
||||||
const stripePromise = loadStripe(
|
const stripePromise = loadStripe(
|
||||||
@@ -24,7 +31,7 @@ export const calculatePrice = (count: number, isAnnual = false) => {
|
|||||||
export const ShowBilling = () => {
|
export const ShowBilling = () => {
|
||||||
const { data: servers } = api.server.all.useQuery(undefined);
|
const { data: servers } = api.server.all.useQuery(undefined);
|
||||||
const { data: admin } = api.admin.one.useQuery();
|
const { data: admin } = api.admin.one.useQuery();
|
||||||
const { data } = api.stripe.getProducts.useQuery();
|
const { data, isLoading } = api.stripe.getProducts.useQuery();
|
||||||
const { mutateAsync: createCheckoutSession } =
|
const { mutateAsync: createCheckoutSession } =
|
||||||
api.stripe.createCheckoutSession.useMutation();
|
api.stripe.createCheckoutSession.useMutation();
|
||||||
|
|
||||||
@@ -96,145 +103,186 @@ export const ShowBilling = () => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{products?.map((product) => {
|
<div className="flex flex-col gap-1.5 mt-4">
|
||||||
const featured = true;
|
<span className="text-base text-primary">
|
||||||
return (
|
Need Help? We are here to help you.
|
||||||
<div key={product.id}>
|
</span>
|
||||||
<section
|
<span className="text-sm text-muted-foreground">
|
||||||
className={clsx(
|
Join to our Discord server and we will help you.
|
||||||
"flex flex-col rounded-3xl border-dashed border-2 px-4 max-w-sm",
|
</span>
|
||||||
featured
|
<Button className="rounded-full bg-[#5965F2] hover:bg-[#4A55E0] w-fit">
|
||||||
? "order-first bg-black border py-8 lg:order-none"
|
<Link
|
||||||
: "lg:py-8",
|
href="https://discord.gg/2tBnJ3jDJc"
|
||||||
)}
|
aria-label="Dokploy on GitHub"
|
||||||
|
target="_blank"
|
||||||
|
className="flex flex-row items-center gap-2 text-white"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
role="img"
|
||||||
|
className="h-6 w-6 fill-white"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
>
|
>
|
||||||
{isAnnual ? (
|
<path d="M20.317 4.3698a19.7913 19.7913 0 00-4.8851-1.5152.0741.0741 0 00-.0785.0371c-.211.3753-.4447.8648-.6083 1.2495-1.8447-.2762-3.68-.2762-5.4868 0-.1636-.3933-.4058-.8742-.6177-1.2495a.077.077 0 00-.0785-.037 19.7363 19.7363 0 00-4.8852 1.515.0699.0699 0 00-.0321.0277C.5334 9.0458-.319 13.5799.0992 18.0578a.0824.0824 0 00.0312.0561c2.0528 1.5076 4.0413 2.4228 5.9929 3.0294a.0777.0777 0 00.0842-.0276c.4616-.6304.8731-1.2952 1.226-1.9942a.076.076 0 00-.0416-.1057c-.6528-.2476-1.2743-.5495-1.8722-.8923a.077.077 0 01-.0076-.1277c.1258-.0943.2517-.1923.3718-.2914a.0743.0743 0 01.0776-.0105c3.9278 1.7933 8.18 1.7933 12.0614 0a.0739.0739 0 01.0785.0095c.1202.099.246.1981.3728.2924a.077.077 0 01-.0066.1276 12.2986 12.2986 0 01-1.873.8914.0766.0766 0 00-.0407.1067c.3604.698.7719 1.3628 1.225 1.9932a.076.076 0 00.0842.0286c1.961-.6067 3.9495-1.5219 6.0023-3.0294a.077.077 0 00.0313-.0552c.5004-5.177-.8382-9.6739-3.5485-13.6604a.061.061 0 00-.0312-.0286zM8.02 15.3312c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9555-2.4189 2.157-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.9555 2.4189-2.1569 2.4189zm7.9748 0c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9554-2.4189 2.1569-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.946 2.4189-2.1568 2.4189Z" />
|
||||||
<div className="flex flex-row gap-2 items-center">
|
</svg>
|
||||||
<p className=" text-2xl font-semibold tracking-tight text-primary ">
|
Join Discord
|
||||||
$ {calculatePrice(serverQuantity, isAnnual).toFixed(2)} USD
|
</Link>
|
||||||
</p>
|
</Button>
|
||||||
|
|
</div>
|
||||||
<p className=" text-base font-semibold tracking-tight text-muted-foreground">
|
{isLoading ? (
|
||||||
${" "}
|
<span className="text-base text-muted-foreground flex flex-row gap-3 items-center justify-center min-h-[10vh]">
|
||||||
{(calculatePrice(serverQuantity, isAnnual) / 12).toFixed(2)}{" "}
|
Loading...
|
||||||
/ Month USD
|
<Loader2 className="animate-spin" />
|
||||||
</p>
|
</span>
|
||||||
</div>
|
) : (
|
||||||
) : (
|
<>
|
||||||
<p className=" text-2xl font-semibold tracking-tight text-primary ">
|
{products?.map((product) => {
|
||||||
$ {calculatePrice(serverQuantity, isAnnual).toFixed(2)} USD
|
const featured = true;
|
||||||
</p>
|
return (
|
||||||
)}
|
<div key={product.id}>
|
||||||
<h3 className="mt-5 font-medium text-lg text-white">
|
<section
|
||||||
{product.name}
|
className={clsx(
|
||||||
</h3>
|
"flex flex-col rounded-3xl border-dashed border-2 px-4 max-w-sm",
|
||||||
<p
|
featured
|
||||||
className={clsx(
|
? "order-first bg-black border py-8 lg:order-none"
|
||||||
"text-sm",
|
: "lg:py-8",
|
||||||
featured ? "text-white" : "text-slate-400",
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{product.description}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<ul
|
|
||||||
role="list"
|
|
||||||
className={clsx(
|
|
||||||
" mt-4 flex flex-col gap-y-2 text-sm",
|
|
||||||
featured ? "text-white" : "text-slate-200",
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{[
|
|
||||||
"All the features of Dokploy",
|
|
||||||
"Unlimited deployments",
|
|
||||||
"Self-hosted on your own infrastructure",
|
|
||||||
"Full access to all deployment features",
|
|
||||||
"Dokploy integration",
|
|
||||||
"Backups",
|
|
||||||
"All Incoming features",
|
|
||||||
].map((feature) => (
|
|
||||||
<li key={feature} className="flex text-muted-foreground">
|
|
||||||
<CheckIcon />
|
|
||||||
<span className="ml-4">{feature}</span>
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
<div className="flex flex-col gap-2 mt-4">
|
|
||||||
<div className="flex items-center gap-2 justify-center">
|
|
||||||
<span className="text-sm text-muted-foreground">
|
|
||||||
{serverQuantity} Servers
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex items-center space-x-2">
|
|
||||||
<Button
|
|
||||||
disabled={serverQuantity <= 1}
|
|
||||||
variant="outline"
|
|
||||||
onClick={() => {
|
|
||||||
if (serverQuantity <= 1) return;
|
|
||||||
|
|
||||||
setServerQuantity(serverQuantity - 1);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<MinusIcon className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
<NumberInput
|
|
||||||
value={serverQuantity}
|
|
||||||
onChange={(e) => {
|
|
||||||
setServerQuantity(e.target.value as unknown as number);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
onClick={() => {
|
|
||||||
setServerQuantity(serverQuantity + 1);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<PlusIcon className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
data?.subscriptions && data?.subscriptions?.length > 0
|
|
||||||
? "justify-between"
|
|
||||||
: "justify-end",
|
|
||||||
"flex flex-row items-center gap-2 mt-4",
|
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{admin?.stripeCustomerId && (
|
{isAnnual ? (
|
||||||
<Button
|
<div className="flex flex-row gap-2 items-center">
|
||||||
variant="secondary"
|
<p className=" text-2xl font-semibold tracking-tight text-primary ">
|
||||||
className="w-full"
|
$ {calculatePrice(serverQuantity, isAnnual).toFixed(2)}{" "}
|
||||||
onClick={async () => {
|
USD
|
||||||
const session = await createCustomerPortalSession();
|
</p>
|
||||||
|
|
|
||||||
window.open(session.url);
|
<p className=" text-base font-semibold tracking-tight text-muted-foreground">
|
||||||
}}
|
${" "}
|
||||||
>
|
{(
|
||||||
Manage Subscription
|
calculatePrice(serverQuantity, isAnnual) / 12
|
||||||
</Button>
|
).toFixed(2)}{" "}
|
||||||
|
/ Month USD
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<p className=" text-2xl font-semibold tracking-tight text-primary ">
|
||||||
|
$ {calculatePrice(serverQuantity, isAnnual).toFixed(2)}{" "}
|
||||||
|
USD
|
||||||
|
</p>
|
||||||
)}
|
)}
|
||||||
|
<h3 className="mt-5 font-medium text-lg text-white">
|
||||||
|
{product.name}
|
||||||
|
</h3>
|
||||||
|
<p
|
||||||
|
className={clsx(
|
||||||
|
"text-sm",
|
||||||
|
featured ? "text-white" : "text-slate-400",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{product.description}
|
||||||
|
</p>
|
||||||
|
|
||||||
{data?.subscriptions?.length === 0 && (
|
<ul
|
||||||
<div className="justify-end w-full">
|
role="list"
|
||||||
|
className={clsx(
|
||||||
|
" mt-4 flex flex-col gap-y-2 text-sm",
|
||||||
|
featured ? "text-white" : "text-slate-200",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{[
|
||||||
|
"All the features of Dokploy",
|
||||||
|
"Unlimited deployments",
|
||||||
|
"Self-hosted on your own infrastructure",
|
||||||
|
"Full access to all deployment features",
|
||||||
|
"Dokploy integration",
|
||||||
|
"Backups",
|
||||||
|
"All Incoming features",
|
||||||
|
].map((feature) => (
|
||||||
|
<li key={feature} className="flex text-muted-foreground">
|
||||||
|
<CheckIcon />
|
||||||
|
<span className="ml-4">{feature}</span>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
<div className="flex flex-col gap-2 mt-4">
|
||||||
|
<div className="flex items-center gap-2 justify-center">
|
||||||
|
<span className="text-sm text-muted-foreground">
|
||||||
|
{serverQuantity} Servers
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
<Button
|
<Button
|
||||||
className="w-full"
|
disabled={serverQuantity <= 1}
|
||||||
onClick={async () => {
|
variant="outline"
|
||||||
handleCheckout(product.id);
|
onClick={() => {
|
||||||
|
if (serverQuantity <= 1) return;
|
||||||
|
|
||||||
|
setServerQuantity(serverQuantity - 1);
|
||||||
}}
|
}}
|
||||||
disabled={serverQuantity < 1}
|
|
||||||
>
|
>
|
||||||
Subscribe
|
<MinusIcon className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
<NumberInput
|
||||||
|
value={serverQuantity}
|
||||||
|
onChange={(e) => {
|
||||||
|
setServerQuantity(
|
||||||
|
e.target.value as unknown as number,
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => {
|
||||||
|
setServerQuantity(serverQuantity + 1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<PlusIcon className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
<div
|
||||||
</div>
|
className={cn(
|
||||||
|
data?.subscriptions && data?.subscriptions?.length > 0
|
||||||
|
? "justify-between"
|
||||||
|
: "justify-end",
|
||||||
|
"flex flex-row items-center gap-2 mt-4",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{admin?.stripeCustomerId && (
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
className="w-full"
|
||||||
|
onClick={async () => {
|
||||||
|
const session = await createCustomerPortalSession();
|
||||||
|
|
||||||
|
window.open(session.url);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Manage Subscription
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{data?.subscriptions?.length === 0 && (
|
||||||
|
<div className="justify-end w-full">
|
||||||
|
<Button
|
||||||
|
className="w-full"
|
||||||
|
onClick={async () => {
|
||||||
|
handleCheckout(product.id);
|
||||||
|
}}
|
||||||
|
disabled={serverQuantity < 1}
|
||||||
|
>
|
||||||
|
Subscribe
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
);
|
||||||
</div>
|
})}
|
||||||
);
|
</>
|
||||||
})}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -52,8 +52,6 @@ export const ProfileForm = () => {
|
|||||||
const { data, refetch } = api.auth.get.useQuery();
|
const { data, refetch } = api.auth.get.useQuery();
|
||||||
const { mutateAsync, isLoading } = api.auth.update.useMutation();
|
const { mutateAsync, isLoading } = api.auth.update.useMutation();
|
||||||
|
|
||||||
const { mutateAsync: generateToken, isLoading: isLoadingToken } =
|
|
||||||
api.auth.generateToken.useMutation();
|
|
||||||
const form = useForm<Profile>({
|
const form = useForm<Profile>({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
email: data?.email || "",
|
email: data?.email || "",
|
||||||
@@ -76,7 +74,7 @@ export const ProfileForm = () => {
|
|||||||
|
|
||||||
const onSubmit = async (values: Profile) => {
|
const onSubmit = async (values: Profile) => {
|
||||||
await mutateAsync({
|
await mutateAsync({
|
||||||
email: values.email,
|
email: values.email.toLowerCase(),
|
||||||
password: values.password,
|
password: values.password,
|
||||||
image: values.image,
|
image: values.image,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ export const AddUser = () => {
|
|||||||
|
|
||||||
const onSubmit = async (data: AddUser) => {
|
const onSubmit = async (data: AddUser) => {
|
||||||
await mutateAsync({
|
await mutateAsync({
|
||||||
email: data.email,
|
email: data.email.toLowerCase(),
|
||||||
})
|
})
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
toast.success("Invitation created");
|
toast.success("Invitation created");
|
||||||
|
|||||||
@@ -1,162 +0,0 @@
|
|||||||
import { AlertBlock } from "@/components/shared/alert-block";
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogDescription,
|
|
||||||
DialogFooter,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
DialogTrigger,
|
|
||||||
} from "@/components/ui/dialog";
|
|
||||||
import {
|
|
||||||
Form,
|
|
||||||
FormControl,
|
|
||||||
FormField,
|
|
||||||
FormItem,
|
|
||||||
FormLabel,
|
|
||||||
FormMessage,
|
|
||||||
} from "@/components/ui/form";
|
|
||||||
import { Input } from "@/components/ui/input";
|
|
||||||
import { api } from "@/utils/api";
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
|
||||||
import { SquarePen } from "lucide-react";
|
|
||||||
import { useEffect } from "react";
|
|
||||||
import { useForm } from "react-hook-form";
|
|
||||||
import { toast } from "sonner";
|
|
||||||
import { z } from "zod";
|
|
||||||
|
|
||||||
const updateUserSchema = z.object({
|
|
||||||
email: z
|
|
||||||
.string()
|
|
||||||
.min(1, "Email is required")
|
|
||||||
.email({ message: "Invalid email" }),
|
|
||||||
password: z.string(),
|
|
||||||
});
|
|
||||||
|
|
||||||
type UpdateUser = z.infer<typeof updateUserSchema>;
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
authId: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const UpdateUser = ({ authId }: Props) => {
|
|
||||||
const utils = api.useUtils();
|
|
||||||
const { mutateAsync, error, isError, isLoading } =
|
|
||||||
api.auth.updateByAdmin.useMutation();
|
|
||||||
const { data } = api.auth.one.useQuery(
|
|
||||||
{
|
|
||||||
id: authId,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
enabled: !!authId,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const form = useForm<UpdateUser>({
|
|
||||||
defaultValues: {
|
|
||||||
email: "",
|
|
||||||
password: "",
|
|
||||||
},
|
|
||||||
resolver: zodResolver(updateUserSchema),
|
|
||||||
});
|
|
||||||
useEffect(() => {
|
|
||||||
if (data) {
|
|
||||||
form.reset({
|
|
||||||
email: data.email || "",
|
|
||||||
password: "",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [data, form, form.reset]);
|
|
||||||
|
|
||||||
const onSubmit = async (formData: UpdateUser) => {
|
|
||||||
await mutateAsync({
|
|
||||||
email: formData.email === data?.email ? null : formData.email,
|
|
||||||
password: formData.password,
|
|
||||||
id: authId,
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
toast.success("User updated succesfully");
|
|
||||||
utils.user.all.invalidate();
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
toast.error("Error to update the user");
|
|
||||||
})
|
|
||||||
.finally(() => {});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Dialog>
|
|
||||||
<DialogTrigger asChild className="w-fit">
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
className=" cursor-pointer space-x-3 w-fit"
|
|
||||||
onSelect={(e) => e.preventDefault()}
|
|
||||||
>
|
|
||||||
<SquarePen className="size-4 text-muted-foreground" />
|
|
||||||
</Button>
|
|
||||||
</DialogTrigger>
|
|
||||||
<DialogContent className="max-h-screen overflow-y-auto sm:max-w-lg">
|
|
||||||
<DialogHeader>
|
|
||||||
<DialogTitle>Update User</DialogTitle>
|
|
||||||
<DialogDescription>Update the user</DialogDescription>
|
|
||||||
</DialogHeader>
|
|
||||||
{isError && <AlertBlock type="error">{error?.message}</AlertBlock>}
|
|
||||||
|
|
||||||
<div className="grid gap-4">
|
|
||||||
<div className="grid items-center gap-4">
|
|
||||||
<Form {...form}>
|
|
||||||
<form
|
|
||||||
onSubmit={form.handleSubmit(onSubmit)}
|
|
||||||
id="hook-form-update-user"
|
|
||||||
className="grid w-full gap-4 "
|
|
||||||
>
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="email"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>Email</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Input placeholder="XNl5C@example.com" {...field} />
|
|
||||||
</FormControl>
|
|
||||||
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="password"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>Password</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
type="password"
|
|
||||||
placeholder="*******"
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<DialogFooter>
|
|
||||||
<Button
|
|
||||||
form="hook-form-update-user"
|
|
||||||
type="submit"
|
|
||||||
isLoading={isLoading}
|
|
||||||
>
|
|
||||||
Update
|
|
||||||
</Button>
|
|
||||||
</DialogFooter>
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
2
apps/dokploy/drizzle/0042_fancy_havok.sql
Normal file
2
apps/dokploy/drizzle/0042_fancy_havok.sql
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE "auth" ADD COLUMN "confirmationToken" text;--> statement-breakpoint
|
||||||
|
ALTER TABLE "auth" ADD COLUMN "confirmationExpiresAt" text;
|
||||||
3968
apps/dokploy/drizzle/meta/0042_snapshot.json
Normal file
3968
apps/dokploy/drizzle/meta/0042_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -295,6 +295,13 @@
|
|||||||
"when": 1729667438853,
|
"when": 1729667438853,
|
||||||
"tag": "0041_huge_bruce_banner",
|
"tag": "0041_huge_bruce_banner",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 42,
|
||||||
|
"version": "6",
|
||||||
|
"when": 1729984439862,
|
||||||
|
"tag": "0042_fancy_havok",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ import { ThemeProvider } from "next-themes";
|
|||||||
import type { AppProps } from "next/app";
|
import type { AppProps } from "next/app";
|
||||||
import { Inter } from "next/font/google";
|
import { Inter } from "next/font/google";
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
|
import Script from "next/script";
|
||||||
import type { ReactElement, ReactNode } from "react";
|
import type { ReactElement, ReactNode } from "react";
|
||||||
|
|
||||||
const inter = Inter({ subsets: ["latin"] });
|
const inter = Inter({ subsets: ["latin"] });
|
||||||
@@ -35,6 +36,14 @@ const MyApp = ({
|
|||||||
`}</style>
|
`}</style>
|
||||||
<Head>
|
<Head>
|
||||||
<title>Dokploy</title>
|
<title>Dokploy</title>
|
||||||
|
{process.env.NEXT_PUBLIC_UMAMI_HOST &&
|
||||||
|
process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID && (
|
||||||
|
<Script
|
||||||
|
defer
|
||||||
|
src={process.env.NEXT_PUBLIC_UMAMI_HOST}
|
||||||
|
data-website-id={process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Head>
|
</Head>
|
||||||
<ThemeProvider
|
<ThemeProvider
|
||||||
attribute="class"
|
attribute="class"
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ import { Head, Html, Main, NextScript } from "next/document";
|
|||||||
export default function Document() {
|
export default function Document() {
|
||||||
return (
|
return (
|
||||||
<Html lang="en" className="font-sans">
|
<Html lang="en" className="font-sans">
|
||||||
<Head />
|
<Head>
|
||||||
|
<link rel="icon" href="/icon.svg" />
|
||||||
|
</Head>
|
||||||
<body className="flex h-full flex-col font-sans">
|
<body className="flex h-full flex-col font-sans">
|
||||||
<Main />
|
<Main />
|
||||||
<NextScript />
|
<NextScript />
|
||||||
|
|||||||
95
apps/dokploy/pages/confirm-email.tsx
Normal file
95
apps/dokploy/pages/confirm-email.tsx
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
import { OnboardingLayout } from "@/components/layouts/onboarding-layout";
|
||||||
|
import { Logo } from "@/components/shared/logo";
|
||||||
|
import { CardDescription, CardTitle } from "@/components/ui/card";
|
||||||
|
import { auth } from "@/server/db/schema";
|
||||||
|
import { IS_CLOUD, updateAuthById } from "@dokploy/server";
|
||||||
|
import { isBefore } from "date-fns";
|
||||||
|
import { eq } from "drizzle-orm";
|
||||||
|
import type { GetServerSidePropsContext } from "next";
|
||||||
|
import Link from "next/link";
|
||||||
|
import type { ReactElement } from "react";
|
||||||
|
|
||||||
|
export default function Home() {
|
||||||
|
return (
|
||||||
|
<div className="flex h-screen w-full items-center justify-center ">
|
||||||
|
<div className="flex flex-col items-center gap-4 w-full">
|
||||||
|
<Link href="/" className="flex flex-row items-center gap-2">
|
||||||
|
<Logo />
|
||||||
|
<span className="font-medium text-sm">Dokploy</span>
|
||||||
|
</Link>
|
||||||
|
<CardTitle className="text-2xl font-bold">Email Confirmed</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Congratulations, your email is confirmed.
|
||||||
|
</CardDescription>
|
||||||
|
<div>
|
||||||
|
<Link href="/" className="w-full text-primary">
|
||||||
|
Click here to login
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Home.getLayout = (page: ReactElement) => {
|
||||||
|
return <OnboardingLayout>{page}</OnboardingLayout>;
|
||||||
|
};
|
||||||
|
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||||
|
if (!IS_CLOUD) {
|
||||||
|
return {
|
||||||
|
redirect: {
|
||||||
|
permanent: true,
|
||||||
|
destination: "/",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const { token } = context.query;
|
||||||
|
|
||||||
|
if (typeof token !== "string") {
|
||||||
|
return {
|
||||||
|
redirect: {
|
||||||
|
permanent: true,
|
||||||
|
destination: "/",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const authR = await db?.query.auth.findFirst({
|
||||||
|
where: eq(auth.confirmationToken, token),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (
|
||||||
|
!authR ||
|
||||||
|
authR?.confirmationToken === null ||
|
||||||
|
authR?.confirmationExpiresAt === null
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
redirect: {
|
||||||
|
permanent: true,
|
||||||
|
destination: "/",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const isExpired = isBefore(new Date(authR.confirmationExpiresAt), new Date());
|
||||||
|
|
||||||
|
if (isExpired) {
|
||||||
|
return {
|
||||||
|
redirect: {
|
||||||
|
permanent: true,
|
||||||
|
destination: "/",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
await updateAuthById(authR.id, {
|
||||||
|
confirmationToken: null,
|
||||||
|
confirmationExpiresAt: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
props: {
|
||||||
|
token: authR.confirmationToken,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Login2FA } from "@/components/auth/login-2fa";
|
import { Login2FA } from "@/components/auth/login-2fa";
|
||||||
import { OnboardingLayout } from "@/components/layouts/onboarding-layout";
|
import { OnboardingLayout } from "@/components/layouts/onboarding-layout";
|
||||||
|
import { AlertBlock } from "@/components/shared/alert-block";
|
||||||
import { Logo } from "@/components/shared/logo";
|
import { Logo } from "@/components/shared/logo";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
@@ -63,7 +64,8 @@ export default function Home({ IS_CLOUD }: Props) {
|
|||||||
is2FAEnabled: false,
|
is2FAEnabled: false,
|
||||||
authId: "",
|
authId: "",
|
||||||
});
|
});
|
||||||
const { mutateAsync, isLoading } = api.auth.login.useMutation();
|
const { mutateAsync, isLoading, error, isError } =
|
||||||
|
api.auth.login.useMutation();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const form = useForm<Login>({
|
const form = useForm<Login>({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
@@ -115,6 +117,12 @@ export default function Home({ IS_CLOUD }: Props) {
|
|||||||
</CardDescription>
|
</CardDescription>
|
||||||
<Card className="mx-auto w-full max-w-lg bg-transparent ">
|
<Card className="mx-auto w-full max-w-lg bg-transparent ">
|
||||||
<div className="p-3.5" />
|
<div className="p-3.5" />
|
||||||
|
{isError && (
|
||||||
|
<AlertBlock type="error" className="mx-4 my-2">
|
||||||
|
<span>{error?.message}</span>
|
||||||
|
</AlertBlock>
|
||||||
|
)}
|
||||||
|
|
||||||
<CardContent>
|
<CardContent>
|
||||||
{!temp.is2FAEnabled ? (
|
{!temp.is2FAEnabled ? (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
@@ -170,12 +178,14 @@ export default function Home({ IS_CLOUD }: Props) {
|
|||||||
|
|
||||||
<div className="flex flex-row justify-between flex-wrap">
|
<div className="flex flex-row justify-between flex-wrap">
|
||||||
<div className="mt-4 text-center text-sm flex flex-row justify-center gap-2">
|
<div className="mt-4 text-center text-sm flex flex-row justify-center gap-2">
|
||||||
<Link
|
{IS_CLOUD && (
|
||||||
className="hover:underline text-muted-foreground"
|
<Link
|
||||||
href="/register"
|
className="hover:underline text-muted-foreground"
|
||||||
>
|
href="/register"
|
||||||
Create an account
|
>
|
||||||
</Link>
|
Create an account
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-4 text-sm flex flex-row justify-center gap-2">
|
<div className="mt-4 text-sm flex flex-row justify-center gap-2">
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import {
|
|||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
import { getUserByToken } from "@dokploy/server";
|
import { IS_CLOUD, getUserByToken } from "@dokploy/server";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { AlertTriangle } from "lucide-react";
|
import { AlertTriangle } from "lucide-react";
|
||||||
import type { GetServerSidePropsContext } from "next";
|
import type { GetServerSidePropsContext } from "next";
|
||||||
@@ -69,9 +69,10 @@ type Register = z.infer<typeof registerSchema>;
|
|||||||
interface Props {
|
interface Props {
|
||||||
token: string;
|
token: string;
|
||||||
invitation: Awaited<ReturnType<typeof getUserByToken>>;
|
invitation: Awaited<ReturnType<typeof getUserByToken>>;
|
||||||
|
isCloud: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Invitation = ({ token, invitation }: Props) => {
|
const Invitation = ({ token, invitation, isCloud }: Props) => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { data } = api.admin.getUserByToken.useQuery(
|
const { data } = api.admin.getUserByToken.useQuery(
|
||||||
{
|
{
|
||||||
@@ -83,7 +84,8 @@ const Invitation = ({ token, invitation }: Props) => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const { mutateAsync, error, isError } = api.auth.createUser.useMutation();
|
const { mutateAsync, error, isError, isSuccess } =
|
||||||
|
api.auth.createUser.useMutation();
|
||||||
|
|
||||||
const form = useForm<Register>({
|
const form = useForm<Register>({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
@@ -112,7 +114,9 @@ const Invitation = ({ token, invitation }: Props) => {
|
|||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
toast.success("User registration succesfuly", {
|
toast.success("User registration succesfuly", {
|
||||||
duration: 2000,
|
description:
|
||||||
|
"Please check your inbox or spam folder to confirm your account.",
|
||||||
|
duration: 100000,
|
||||||
});
|
});
|
||||||
router.push("/dashboard/projects");
|
router.push("/dashboard/projects");
|
||||||
})
|
})
|
||||||
@@ -146,6 +150,7 @@ const Invitation = ({ token, invitation }: Props) => {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form
|
<form
|
||||||
@@ -210,6 +215,25 @@ const Invitation = ({ token, invitation }: Props) => {
|
|||||||
Register
|
Register
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="mt-4 text-sm flex flex-row justify-between gap-2 w-full">
|
||||||
|
{isCloud && (
|
||||||
|
<>
|
||||||
|
<Link
|
||||||
|
className="hover:underline text-muted-foreground"
|
||||||
|
href="/"
|
||||||
|
>
|
||||||
|
Login
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
className="hover:underline text-muted-foreground"
|
||||||
|
href="/send-reset-password"
|
||||||
|
>
|
||||||
|
Lost your password?
|
||||||
|
</Link>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
@@ -250,6 +274,7 @@ export async function getServerSideProps(ctx: GetServerSidePropsContext) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
|
isCloud: IS_CLOUD,
|
||||||
token: token,
|
token: token,
|
||||||
invitation: invitation,
|
invitation: invitation,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { AlertBlock } from "@/components/shared/alert-block";
|
||||||
import { Logo } from "@/components/shared/logo";
|
import { Logo } from "@/components/shared/logo";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
@@ -72,7 +73,8 @@ interface Props {
|
|||||||
|
|
||||||
const Register = ({ isCloud }: Props) => {
|
const Register = ({ isCloud }: Props) => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { mutateAsync, error, isError } = api.auth.createAdmin.useMutation();
|
const { mutateAsync, error, isError, data } =
|
||||||
|
api.auth.createAdmin.useMutation();
|
||||||
|
|
||||||
const form = useForm<Register>({
|
const form = useForm<Register>({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
@@ -89,14 +91,16 @@ const Register = ({ isCloud }: Props) => {
|
|||||||
|
|
||||||
const onSubmit = async (values: Register) => {
|
const onSubmit = async (values: Register) => {
|
||||||
await mutateAsync({
|
await mutateAsync({
|
||||||
email: values.email,
|
email: values.email.toLowerCase(),
|
||||||
password: values.password,
|
password: values.password,
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
toast.success("User registration succesfuly", {
|
toast.success("User registration succesfuly", {
|
||||||
duration: 2000,
|
duration: 2000,
|
||||||
});
|
});
|
||||||
router.push("/");
|
if (!isCloud) {
|
||||||
|
router.push("/");
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((e) => e);
|
.catch((e) => e);
|
||||||
};
|
};
|
||||||
@@ -130,6 +134,14 @@ const Register = ({ isCloud }: Props) => {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{data && (
|
||||||
|
<AlertBlock type="success" className="mx-4 my-2">
|
||||||
|
<span>
|
||||||
|
Registration succesfuly, Please check your inbox or spam
|
||||||
|
folder to confirm your account.
|
||||||
|
</span>
|
||||||
|
</AlertBlock>
|
||||||
|
)}
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form
|
<form
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ const Home: NextPage = () => {
|
|||||||
const [spec, setSpec] = useState({});
|
const [spec, setSpec] = useState({});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Esto solo se ejecutará en el cliente
|
|
||||||
if (data) {
|
if (data) {
|
||||||
const protocolAndHost = `${window.location.protocol}//${window.location.host}/api`;
|
const protocolAndHost = `${window.location.protocol}//${window.location.host}/api`;
|
||||||
const newSpec = {
|
const newSpec = {
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.4 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB |
@@ -6,7 +6,6 @@ import {
|
|||||||
apiRemoveUser,
|
apiRemoveUser,
|
||||||
users,
|
users,
|
||||||
} from "@/server/db/schema";
|
} from "@/server/db/schema";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
createInvitation,
|
createInvitation,
|
||||||
findAdminById,
|
findAdminById,
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import {
|
|||||||
apiFindOneAuth,
|
apiFindOneAuth,
|
||||||
apiLogin,
|
apiLogin,
|
||||||
apiUpdateAuth,
|
apiUpdateAuth,
|
||||||
apiUpdateAuthByAdmin,
|
|
||||||
apiVerify2FA,
|
apiVerify2FA,
|
||||||
apiVerifyLogin2FA,
|
apiVerifyLogin2FA,
|
||||||
auth,
|
auth,
|
||||||
} from "@/server/db/schema";
|
} from "@/server/db/schema";
|
||||||
|
import { WEBSITE_URL } from "@/server/utils/stripe";
|
||||||
import {
|
import {
|
||||||
IS_CLOUD,
|
IS_CLOUD,
|
||||||
createAdmin,
|
createAdmin,
|
||||||
@@ -53,6 +53,11 @@ export const authRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const newAdmin = await createAdmin(input);
|
const newAdmin = await createAdmin(input);
|
||||||
|
|
||||||
|
if (IS_CLOUD) {
|
||||||
|
await sendVerificationEmail(newAdmin.id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
const session = await lucia.createSession(newAdmin.id || "", {});
|
const session = await lucia.createSession(newAdmin.id || "", {});
|
||||||
ctx.res.appendHeader(
|
ctx.res.appendHeader(
|
||||||
"Set-Cookie",
|
"Set-Cookie",
|
||||||
@@ -60,7 +65,12 @@ export const authRouter = createTRPCRouter({
|
|||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw new TRPCError({
|
||||||
|
code: "BAD_REQUEST",
|
||||||
|
// @ts-ignore
|
||||||
|
message: `Error: ${error?.code === "23505" ? "Email already exists" : "Error to create admin"}`,
|
||||||
|
cause: error,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
createUser: publicProcedure
|
createUser: publicProcedure
|
||||||
@@ -74,7 +84,13 @@ export const authRouter = createTRPCRouter({
|
|||||||
message: "Invalid token",
|
message: "Invalid token",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const newUser = await createUser(input);
|
const newUser = await createUser(input);
|
||||||
|
|
||||||
|
if (IS_CLOUD) {
|
||||||
|
await sendVerificationEmail(token.authId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
const session = await lucia.createSession(newUser?.authId || "", {});
|
const session = await lucia.createSession(newUser?.authId || "", {});
|
||||||
ctx.res.appendHeader(
|
ctx.res.appendHeader(
|
||||||
"Set-Cookie",
|
"Set-Cookie",
|
||||||
@@ -106,6 +122,15 @@ export const authRouter = createTRPCRouter({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (auth?.confirmationToken && IS_CLOUD) {
|
||||||
|
await sendVerificationEmail(auth.id);
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "BAD_REQUEST",
|
||||||
|
message:
|
||||||
|
"Email not confirmed, we have sent you a confirmation email please check your inbox.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (auth?.is2FAEnabled) {
|
if (auth?.is2FAEnabled) {
|
||||||
return {
|
return {
|
||||||
is2FAEnabled: true,
|
is2FAEnabled: true,
|
||||||
@@ -126,7 +151,7 @@ export const authRouter = createTRPCRouter({
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
message: "Credentials do not match",
|
message: `Error: ${error instanceof Error ? error.message : "Error to login"}`,
|
||||||
cause: error,
|
cause: error,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -151,7 +176,7 @@ export const authRouter = createTRPCRouter({
|
|||||||
.input(apiUpdateAuth)
|
.input(apiUpdateAuth)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
const auth = await updateAuthById(ctx.user.authId, {
|
const auth = await updateAuthById(ctx.user.authId, {
|
||||||
...(input.email && { email: input.email }),
|
...(input.email && { email: input.email.toLowerCase() }),
|
||||||
...(input.password && {
|
...(input.password && {
|
||||||
password: bcrypt.hashSync(input.password, 10),
|
password: bcrypt.hashSync(input.password, 10),
|
||||||
}),
|
}),
|
||||||
@@ -183,19 +208,6 @@ export const authRouter = createTRPCRouter({
|
|||||||
return auth;
|
return auth;
|
||||||
}),
|
}),
|
||||||
|
|
||||||
updateByAdmin: protectedProcedure
|
|
||||||
.input(apiUpdateAuthByAdmin)
|
|
||||||
.mutation(async ({ input }) => {
|
|
||||||
const auth = await updateAuthById(input.id, {
|
|
||||||
...(input.email && { email: input.email }),
|
|
||||||
...(input.password && {
|
|
||||||
password: bcrypt.hashSync(input.password, 10),
|
|
||||||
}),
|
|
||||||
...(input.image && { image: input.image }),
|
|
||||||
});
|
|
||||||
|
|
||||||
return auth;
|
|
||||||
}),
|
|
||||||
generate2FASecret: protectedProcedure.query(async ({ ctx }) => {
|
generate2FASecret: protectedProcedure.query(async ({ ctx }) => {
|
||||||
return await generate2FASecret(ctx.user.authId);
|
return await generate2FASecret(ctx.user.authId);
|
||||||
}),
|
}),
|
||||||
@@ -236,9 +248,6 @@ export const authRouter = createTRPCRouter({
|
|||||||
});
|
});
|
||||||
return auth;
|
return auth;
|
||||||
}),
|
}),
|
||||||
verifyToken: protectedProcedure.mutation(async () => {
|
|
||||||
return true;
|
|
||||||
}),
|
|
||||||
sendResetPasswordEmail: publicProcedure
|
sendResetPasswordEmail: publicProcedure
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
@@ -270,7 +279,7 @@ export const authRouter = createTRPCRouter({
|
|||||||
).toISOString(),
|
).toISOString(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const email = await sendEmailNotification(
|
await sendEmailNotification(
|
||||||
{
|
{
|
||||||
fromAddress: process.env.SMTP_FROM_ADDRESS || "",
|
fromAddress: process.env.SMTP_FROM_ADDRESS || "",
|
||||||
toAddresses: [authR.email],
|
toAddresses: [authR.email],
|
||||||
@@ -283,7 +292,7 @@ export const authRouter = createTRPCRouter({
|
|||||||
`
|
`
|
||||||
Reset your password by clicking the link below:
|
Reset your password by clicking the link below:
|
||||||
The link will expire in 24 hours.
|
The link will expire in 24 hours.
|
||||||
<a href="http://localhost:3000/reset-password?token=${token}">
|
<a href="${WEBSITE_URL}/reset-password?token=${token}">
|
||||||
Reset Password
|
Reset Password
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
@@ -334,6 +343,90 @@ export const authRouter = createTRPCRouter({
|
|||||||
password: bcrypt.hashSync(input.password, 10),
|
password: bcrypt.hashSync(input.password, 10),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}),
|
||||||
|
confirmEmail: adminProcedure
|
||||||
|
.input(
|
||||||
|
z.object({
|
||||||
|
confirmationToken: z.string().min(1),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
if (!IS_CLOUD) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "NOT_FOUND",
|
||||||
|
message: "Functionality not available in cloud version",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const authR = await db.query.auth.findFirst({
|
||||||
|
where: eq(auth.confirmationToken, input.confirmationToken),
|
||||||
|
});
|
||||||
|
if (!authR || authR.confirmationExpiresAt === null) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "NOT_FOUND",
|
||||||
|
message: "Token not found",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (authR.confirmationToken !== input.confirmationToken) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "NOT_FOUND",
|
||||||
|
message: "Confirmation Token not found",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const isExpired = isBefore(
|
||||||
|
new Date(authR.confirmationExpiresAt),
|
||||||
|
new Date(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isExpired) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "NOT_FOUND",
|
||||||
|
message: "Confirmation Token expired",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
1;
|
||||||
|
await updateAuthById(authR.id, {
|
||||||
|
confirmationToken: null,
|
||||||
|
confirmationExpiresAt: null,
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const sendVerificationEmail = async (authId: string) => {
|
||||||
|
const token = nanoid();
|
||||||
|
const result = await updateAuthById(authId, {
|
||||||
|
confirmationToken: token,
|
||||||
|
confirmationExpiresAt: new Date(
|
||||||
|
new Date().getTime() + 24 * 60 * 60 * 1000,
|
||||||
|
).toISOString(),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "BAD_REQUEST",
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await sendEmailNotification(
|
||||||
|
{
|
||||||
|
fromAddress: process.env.SMTP_FROM_ADDRESS || "",
|
||||||
|
toAddresses: [result?.email],
|
||||||
|
smtpServer: process.env.SMTP_SERVER || "",
|
||||||
|
smtpPort: Number(process.env.SMTP_PORT),
|
||||||
|
username: process.env.SMTP_USERNAME || "",
|
||||||
|
password: process.env.SMTP_PASSWORD || "",
|
||||||
|
},
|
||||||
|
"Confirm your email | Dokploy",
|
||||||
|
`
|
||||||
|
Welcome to Dokploy!
|
||||||
|
Please confirm your email by clicking the link below:
|
||||||
|
<a href="${WEBSITE_URL}/confirm-email?token=${result?.confirmationToken}">
|
||||||
|
Confirm Email
|
||||||
|
</a>
|
||||||
|
`,
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { Inter, Lexend } from "next/font/google";
|
import { Inter, Lexend } from "next/font/google";
|
||||||
import "@/styles/tailwind.css";
|
import "@/styles/tailwind.css";
|
||||||
import GoogleAnalytics from "@/components/analitycs/google";
|
|
||||||
|
|
||||||
import { NextIntlClientProvider } from "next-intl";
|
import { NextIntlClientProvider } from "next-intl";
|
||||||
import { getMessages } from "next-intl/server";
|
import { getMessages } from "next-intl/server";
|
||||||
|
|
||||||
@@ -88,7 +86,14 @@ export default async function RootLayout({
|
|||||||
lang={locale}
|
lang={locale}
|
||||||
className={clsx("h-full scroll-smooth", inter.variable, lexend.variable)}
|
className={clsx("h-full scroll-smooth", inter.variable, lexend.variable)}
|
||||||
>
|
>
|
||||||
<GoogleAnalytics />
|
<head>
|
||||||
|
<script
|
||||||
|
defer
|
||||||
|
src="https://umami.dokploy.com/script.js"
|
||||||
|
data-website-id="7d1422e4-3776-4870-8145-7d7b2075d470"
|
||||||
|
/>
|
||||||
|
</head>
|
||||||
|
{/* <GoogleAnalytics /> */}
|
||||||
<body className="flex h-full flex-col">
|
<body className="flex h-full flex-col">
|
||||||
<NextIntlClientProvider messages={messages}>
|
<NextIntlClientProvider messages={messages}>
|
||||||
<Header />
|
<Header />
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ export const auth = pgTable("auth", {
|
|||||||
.$defaultFn(() => new Date().toISOString()),
|
.$defaultFn(() => new Date().toISOString()),
|
||||||
resetPasswordToken: text("resetPasswordToken"),
|
resetPasswordToken: text("resetPasswordToken"),
|
||||||
resetPasswordExpiresAt: text("resetPasswordExpiresAt"),
|
resetPasswordExpiresAt: text("resetPasswordExpiresAt"),
|
||||||
|
confirmationToken: text("confirmationToken"),
|
||||||
|
confirmationExpiresAt: text("confirmationExpiresAt"),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const authRelations = relations(auth, ({ many }) => ({
|
export const authRelations = relations(auth, ({ many }) => ({
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export const createInvitation = async (
|
|||||||
const result = await tx
|
const result = await tx
|
||||||
.insert(auth)
|
.insert(auth)
|
||||||
.values({
|
.values({
|
||||||
email: input.email,
|
email: input.email.toLowerCase(),
|
||||||
rol: "user",
|
rol: "user",
|
||||||
password: bcrypt.hashSync("01231203012312", 10),
|
password: bcrypt.hashSync("01231203012312", 10),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export const createAdmin = async (input: typeof apiCreateAdmin._type) => {
|
|||||||
const newAuth = await tx
|
const newAuth = await tx
|
||||||
.insert(auth)
|
.insert(auth)
|
||||||
.values({
|
.values({
|
||||||
email: input.email,
|
email: input.email.toLowerCase(),
|
||||||
password: hashedPassword,
|
password: hashedPassword,
|
||||||
rol: "admin",
|
rol: "admin",
|
||||||
})
|
})
|
||||||
@@ -93,7 +93,7 @@ export const findAuthByEmail = async (email: string) => {
|
|||||||
if (!result) {
|
if (!result) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "NOT_FOUND",
|
code: "NOT_FOUND",
|
||||||
message: "Auth not found",
|
message: "User not found",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
@@ -13454,7 +13454,7 @@ snapshots:
|
|||||||
eslint: 8.45.0
|
eslint: 8.45.0
|
||||||
eslint-import-resolver-node: 0.3.9
|
eslint-import-resolver-node: 0.3.9
|
||||||
eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.21.0(eslint@8.45.0)(typescript@5.1.6))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.45.0))(eslint@8.45.0)
|
eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.21.0(eslint@8.45.0)(typescript@5.1.6))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.45.0))(eslint@8.45.0)
|
||||||
eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.21.0(eslint@8.45.0)(typescript@5.1.6))(eslint-import-resolver-typescript@3.6.1)(eslint@8.45.0)
|
eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.21.0(eslint@8.45.0)(typescript@5.1.6))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.21.0(eslint@8.45.0)(typescript@5.1.6))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.45.0))(eslint@8.45.0))(eslint@8.45.0)
|
||||||
eslint-plugin-jsx-a11y: 6.9.0(eslint@8.45.0)
|
eslint-plugin-jsx-a11y: 6.9.0(eslint@8.45.0)
|
||||||
eslint-plugin-react: 7.35.0(eslint@8.45.0)
|
eslint-plugin-react: 7.35.0(eslint@8.45.0)
|
||||||
eslint-plugin-react-hooks: 5.0.0-canary-7118f5dd7-20230705(eslint@8.45.0)
|
eslint-plugin-react-hooks: 5.0.0-canary-7118f5dd7-20230705(eslint@8.45.0)
|
||||||
@@ -13478,7 +13478,7 @@ snapshots:
|
|||||||
enhanced-resolve: 5.17.1
|
enhanced-resolve: 5.17.1
|
||||||
eslint: 8.45.0
|
eslint: 8.45.0
|
||||||
eslint-module-utils: 2.8.1(@typescript-eslint/parser@6.21.0(eslint@8.45.0)(typescript@5.1.6))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.21.0(eslint@8.45.0)(typescript@5.1.6))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.45.0))(eslint@8.45.0))(eslint@8.45.0)
|
eslint-module-utils: 2.8.1(@typescript-eslint/parser@6.21.0(eslint@8.45.0)(typescript@5.1.6))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.21.0(eslint@8.45.0)(typescript@5.1.6))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.45.0))(eslint@8.45.0))(eslint@8.45.0)
|
||||||
eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.21.0(eslint@8.45.0)(typescript@5.1.6))(eslint-import-resolver-typescript@3.6.1)(eslint@8.45.0)
|
eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.21.0(eslint@8.45.0)(typescript@5.1.6))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.21.0(eslint@8.45.0)(typescript@5.1.6))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.45.0))(eslint@8.45.0))(eslint@8.45.0)
|
||||||
fast-glob: 3.3.2
|
fast-glob: 3.3.2
|
||||||
get-tsconfig: 4.7.5
|
get-tsconfig: 4.7.5
|
||||||
is-core-module: 2.15.0
|
is-core-module: 2.15.0
|
||||||
@@ -13500,7 +13500,7 @@ snapshots:
|
|||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- supports-color
|
- supports-color
|
||||||
|
|
||||||
eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.21.0(eslint@8.45.0)(typescript@5.1.6))(eslint-import-resolver-typescript@3.6.1)(eslint@8.45.0):
|
eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.21.0(eslint@8.45.0)(typescript@5.1.6))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.21.0(eslint@8.45.0)(typescript@5.1.6))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.45.0))(eslint@8.45.0))(eslint@8.45.0):
|
||||||
dependencies:
|
dependencies:
|
||||||
array-includes: 3.1.8
|
array-includes: 3.1.8
|
||||||
array.prototype.findlastindex: 1.2.5
|
array.prototype.findlastindex: 1.2.5
|
||||||
|
|||||||
Reference in New Issue
Block a user