mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-19 02:15:17 +00:00
refactor(passkeys): list passkeys via tRPC instead of better-auth client atom
This commit is contained in:
@@ -16,10 +16,17 @@ import {
|
|||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { authClient } from "@/lib/auth-client";
|
import { authClient } from "@/lib/auth-client";
|
||||||
|
import { api } from "@/utils/api";
|
||||||
|
|
||||||
export const ManagePasskeys = () => {
|
export const ManagePasskeys = () => {
|
||||||
|
const utils = api.useUtils();
|
||||||
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
||||||
const { data: passkeys, isPending, refetch } = authClient.useListPasskeys();
|
const { data: passkeys, isLoading } = api.user.listPasskeys.useQuery(
|
||||||
|
undefined,
|
||||||
|
{
|
||||||
|
enabled: isDialogOpen,
|
||||||
|
},
|
||||||
|
);
|
||||||
const [name, setName] = useState("");
|
const [name, setName] = useState("");
|
||||||
const [isAdding, setIsAdding] = useState(false);
|
const [isAdding, setIsAdding] = useState(false);
|
||||||
const [deletingId, setDeletingId] = useState<string | null>(null);
|
const [deletingId, setDeletingId] = useState<string | null>(null);
|
||||||
@@ -39,7 +46,7 @@ export const ManagePasskeys = () => {
|
|||||||
|
|
||||||
toast.success("Passkey added successfully");
|
toast.success("Passkey added successfully");
|
||||||
setName("");
|
setName("");
|
||||||
refetch();
|
utils.user.listPasskeys.invalidate();
|
||||||
} catch {
|
} catch {
|
||||||
toast.error("Failed to add passkey");
|
toast.error("Failed to add passkey");
|
||||||
} finally {
|
} finally {
|
||||||
@@ -58,7 +65,7 @@ export const ManagePasskeys = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toast.success("Passkey removed");
|
toast.success("Passkey removed");
|
||||||
refetch();
|
utils.user.listPasskeys.invalidate();
|
||||||
} catch {
|
} catch {
|
||||||
toast.error("Failed to remove passkey");
|
toast.error("Failed to remove passkey");
|
||||||
} finally {
|
} finally {
|
||||||
@@ -84,7 +91,7 @@ export const ManagePasskeys = () => {
|
|||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
{isPending ? (
|
{isLoading ? (
|
||||||
<div className="flex flex-row gap-2 items-center justify-center text-sm text-muted-foreground min-h-[10vh]">
|
<div className="flex flex-row gap-2 items-center justify-center text-sm text-muted-foreground min-h-[10vh]">
|
||||||
<span>Loading...</span>
|
<span>Loading...</span>
|
||||||
<Loader2 className="animate-spin size-4" />
|
<Loader2 className="animate-spin size-4" />
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
createOrganizationUserWithCredentials,
|
createOrganizationUserWithCredentials,
|
||||||
findNotificationById,
|
findNotificationById,
|
||||||
findOrganizationById,
|
findOrganizationById,
|
||||||
|
findPasskeysByUserId,
|
||||||
findUserById,
|
findUserById,
|
||||||
getDokployUrl,
|
getDokployUrl,
|
||||||
getUserByToken,
|
getUserByToken,
|
||||||
@@ -173,6 +174,9 @@ export const userRouter = createTRPCRouter({
|
|||||||
getPermissions: protectedProcedure.query(async ({ ctx }) => {
|
getPermissions: protectedProcedure.query(async ({ ctx }) => {
|
||||||
return resolvePermissions(ctx);
|
return resolvePermissions(ctx);
|
||||||
}),
|
}),
|
||||||
|
listPasskeys: protectedProcedure.query(async ({ ctx }) => {
|
||||||
|
return findPasskeysByUserId(ctx.user.id);
|
||||||
|
}),
|
||||||
haveRootAccess: protectedProcedure.query(async ({ ctx }) => {
|
haveRootAccess: protectedProcedure.query(async ({ ctx }) => {
|
||||||
if (!IS_CLOUD) {
|
if (!IS_CLOUD) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import {
|
|||||||
apikey,
|
apikey,
|
||||||
invitation,
|
invitation,
|
||||||
member,
|
member,
|
||||||
|
passkey,
|
||||||
user,
|
user,
|
||||||
} from "@dokploy/server/db/schema";
|
} from "@dokploy/server/db/schema";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import * as bcrypt from "bcrypt";
|
import * as bcrypt from "bcrypt";
|
||||||
import { and, eq } from "drizzle-orm";
|
import { and, desc, eq } from "drizzle-orm";
|
||||||
import { auth } from "../lib/auth";
|
import { auth } from "../lib/auth";
|
||||||
|
|
||||||
export type User = typeof user.$inferSelect;
|
export type User = typeof user.$inferSelect;
|
||||||
@@ -396,6 +397,21 @@ export const findMemberById = async (
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const findPasskeysByUserId = async (userId: string) => {
|
||||||
|
return db.query.passkey.findMany({
|
||||||
|
where: eq(passkey.userId, userId),
|
||||||
|
columns: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
deviceType: true,
|
||||||
|
backedUp: true,
|
||||||
|
createdAt: true,
|
||||||
|
aaguid: true,
|
||||||
|
},
|
||||||
|
orderBy: [desc(passkey.createdAt)],
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const createOrganizationUserWithCredentials = async ({
|
export const createOrganizationUserWithCredentials = async ({
|
||||||
organizationId,
|
organizationId,
|
||||||
email,
|
email,
|
||||||
|
|||||||
Reference in New Issue
Block a user