From f9c6646b5cbb94dc8eaefd705d6616cce8270615 Mon Sep 17 00:00:00 2001 From: Divyanshgupta030 <145568562+Divyanshgupta030@users.noreply.github.com> Date: Tue, 26 Nov 2024 21:32:51 +0530 Subject: [PATCH] update auth to better-auth v1 --- .../components/custom/account-switcher.tsx | 33 +++++++++++--- apps/www/package.json | 2 +- packages/auth/package.json | 4 +- packages/auth/tsconfig.json | 2 +- .../20241126154111_final_auth/migration.sql | 31 +++++++++++++ packages/database/prisma/schema.prisma | 36 +++++++++------ packages/typescript-config/base.json | 2 +- pnpm-lock.yaml | 44 +++++++++---------- 8 files changed, 106 insertions(+), 48 deletions(-) create mode 100644 packages/database/prisma/migrations/20241126154111_final_auth/migration.sql diff --git a/apps/www/components/custom/account-switcher.tsx b/apps/www/components/custom/account-switcher.tsx index 884e986..1ef4127 100644 --- a/apps/www/components/custom/account-switcher.tsx +++ b/apps/www/components/custom/account-switcher.tsx @@ -1,6 +1,7 @@ "use client"; import { authClient } from "@/lib/auth-client"; import { Session } from "@repo/auth"; +import Link from "next/link"; import { useRouter } from "next/navigation"; interface Props { session: Session[] | null; @@ -8,10 +9,10 @@ interface Props { } export default function AccountSwitcher({ session, activeSession }: Props) { const router = useRouter(); - const onSelect = async (sessionId: string) => { - console.log(sessionId); + const onSelect = async (token: string) => { + console.log(token); const active = await authClient.multiSession.setActive({ - sessionId: sessionId, + sessionToken: token, }); console.log(active); @@ -29,20 +30,27 @@ export default function AccountSwitcher({ session, activeSession }: Props) { }, }); }; + if (!activeSession || !session) { return
loading sessions
; } + const handleCurrentSignOut = async () => { + await authClient.multiSession.revoke({ + sessionToken: activeSession?.session.token + }); + window.location.reload(); + }; return (