From 6ab3ae196b540bbc69cdd61aaf67e921e0342093 Mon Sep 17 00:00:00 2001 From: Divyanshgupta030 <145568562+Divyanshgupta030@users.noreply.github.com> Date: Sat, 16 Nov 2024 21:29:36 +0530 Subject: [PATCH 1/3] auth fix --- apps/app/middleware.ts | 2 +- apps/app/package.json | 10 +- apps/triggers/package.json | 2 +- apps/www/app/(auth)/dashboard/page.tsx | 22 +- .../components/custom/account-switcher.tsx | 15 +- apps/www/package.json | 2 +- apps/www/tsconfig.json | 21 +- package.json | 3 +- packages/auth/package.json | 6 +- packages/auth/src/auth.ts | 12 +- packages/auth/tsconfig.json | 5 + packages/typescript-config/base.json | 4 +- pnpm-lock.yaml | 1217 ++++++++++------- 13 files changed, 770 insertions(+), 551 deletions(-) create mode 100644 packages/auth/tsconfig.json diff --git a/apps/app/middleware.ts b/apps/app/middleware.ts index ffe541d..be4464a 100644 --- a/apps/app/middleware.ts +++ b/apps/app/middleware.ts @@ -1,5 +1,5 @@ import { betterFetch } from "@better-fetch/fetch"; -import type { Session } from "better-auth/types"; +import type { Session } from "@repo/auth"; import { NextResponse, type NextRequest } from "next/server"; const baseDomain = process.env.NODE_ENV === "production" diff --git a/apps/app/package.json b/apps/app/package.json index 3b67683..2c7cdf4 100644 --- a/apps/app/package.json +++ b/apps/app/package.json @@ -13,6 +13,7 @@ "format:check": "prettier --check \"**/*.{ts,tsx,mdx}\" --cache" }, "dependencies": { + "@better-fetch/fetch": "^1.1.12", "@hookform/resolvers": "^3.9.1", "@radix-ui/react-alert-dialog": "^1.1.2", "@radix-ui/react-avatar": "^1.1.1", @@ -29,12 +30,16 @@ "@radix-ui/react-toggle": "^1.1.0", "@radix-ui/react-toggle-group": "^1.1.0", "@radix-ui/react-tooltip": "^1.1.3", + "@repo/auth": "workspace:*", + "@repo/db": "workspace:*", + "@repo/types": "workspace:*", "@tabler/icons-react": "^3.21.0", "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", "cmdk": "1.0.0", "contentlayer2": "^0.5.3", "framer-motion": "^11.11.11", + "geist": "^1.3.1", "input-otp": "^1.4.1", "lucide-react": "^0.454.0", "next": "15.0.2", @@ -47,10 +52,7 @@ "sonner": "^1.7.0", "tailwind-merge": "^2.5.4", "tailwindcss-animate": "^1.0.7", - "zod": "^3.23.8", - "@repo/auth": "workspace:*", - "@repo/db": "workspace:*", - "@repo/types": "workspace:*" + "zod": "^3.23.8" }, "devDependencies": { "@types/node": "^20", diff --git a/apps/triggers/package.json b/apps/triggers/package.json index 066f478..a5fb182 100644 --- a/apps/triggers/package.json +++ b/apps/triggers/package.json @@ -2,7 +2,7 @@ "name": "triggers", "version": "1.0.0", "scripts": { - "dev": "pnpm dlx trigger.dev@latest dev", + "trigger": "pnpm dlx trigger.dev@latest dev", "deploy": "pnpm dlx trigger.dev@latest deploy" }, "keywords": [], diff --git a/apps/www/app/(auth)/dashboard/page.tsx b/apps/www/app/(auth)/dashboard/page.tsx index 6a112df..8ad8680 100644 --- a/apps/www/app/(auth)/dashboard/page.tsx +++ b/apps/www/app/(auth)/dashboard/page.tsx @@ -1,9 +1,25 @@ +"use client" import AccountSwitcher from "@/components/custom/account-switcher"; +import { authClient } from "@/lib/auth-client"; import { getMultipleSessions, getSession } from "@/lib/server"; +import {Session} from "@repo/auth" +import { usePathname } from "next/navigation"; +import { use, useEffect, useState } from "react"; -export default async function page() { - const session = await getSession(); - const multipleSessions = await getMultipleSessions(); +export default function page() { + const [session, setSession] = useState(null); + const [multipleSessions, setMultipleSessions] = useState(null) + useEffect(() => { + async function getData() { + const session = await authClient.getSession(); + const multipleSessions = + await authClient.multiSession.listDeviceSessions(); + setSession(session.data); + setMultipleSessions(multipleSessions.data); + console.log("i am here") + } + getData(); + }, []); return (
diff --git a/apps/www/components/custom/account-switcher.tsx b/apps/www/components/custom/account-switcher.tsx index 8d61c59..21eb9f7 100644 --- a/apps/www/components/custom/account-switcher.tsx +++ b/apps/www/components/custom/account-switcher.tsx @@ -3,8 +3,8 @@ import { authClient } from "@/lib/auth-client"; import { Session } from "@repo/auth"; import { useRouter } from "next/navigation"; interface Props { - session: Session[]; - activeSession: Session; + session: Session[] | null; + activeSession: Session | null } export default function AccountSwitcher({ session, activeSession }: Props) { const router = useRouter(); @@ -15,17 +15,24 @@ export default function AccountSwitcher({ session, activeSession }: Props) { }); console.log(active); - router.refresh(); + window.location.reload() }; const handleSignOut = async () => { await authClient.signOut({ fetchOptions: { onSuccess: () => { - router.push("/auth"); + router.push("/auth") }, + onError: (ctx) => { + console.log("error",ctx.error) + } }, }); }; + if(!activeSession || !session ){ + return
loading sessions
+ + } return (