From 16af3c31f149dc28d55687268f8d250bf572456c Mon Sep 17 00:00:00 2001
From: Anthony Vargas <90121982+Speedrunyourknowledge@users.noreply.github.com>
Date: Sat, 19 Apr 2025 01:39:58 -0400
Subject: [PATCH 01/13] update: prisma schema with better auth cli
---
calc-backend/prisma/schema.prisma | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/calc-backend/prisma/schema.prisma b/calc-backend/prisma/schema.prisma
index cc9badf..cf4ae32 100644
--- a/calc-backend/prisma/schema.prisma
+++ b/calc-backend/prisma/schema.prisma
@@ -6,7 +6,7 @@
generator client {
provider = "prisma-client-js"
- output = "./client"
+ output = "./client"
}
datasource db {
@@ -65,14 +65,14 @@ model Account {
}
model Verification {
- id String @id @default(cuid()) @map("_id")
- identifier String
- value String
- expiresAt DateTime
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
-
- @@map("verification")
+ id String @id @default(cuid()) @map("_id")
+ identifier String
+ value String
+ expiresAt DateTime
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+
+ @@map("verification")
}
model Func {
From 4bb4d795d62d2fc159ebf44b07e297fc4634b0da Mon Sep 17 00:00:00 2001
From: Anthony Vargas <90121982+Speedrunyourknowledge@users.noreply.github.com>
Date: Sat, 19 Apr 2025 02:38:11 -0400
Subject: [PATCH 02/13] test: get session on client
---
calc-backend/src/index.ts | 9 +----
calc-backend/src/lib/auth.ts | 4 +--
calc-frontend/src/App/App.tsx | 3 +-
calc-frontend/src/App/RootLayout.tsx | 36 ++++---------------
.../components/Custom/DerivCustomGraph.tsx | 1 -
.../src/components/Custom/IntCustomGraph.tsx | 1 -
.../src/components/ui/SaveFunctionButton.tsx | 16 ++-------
calc-frontend/src/lib/auth-client.ts | 4 +--
calc-frontend/src/pages/CustomDerivative.tsx | 17 ++++-----
calc-frontend/src/pages/CustomIntegral.tsx | 16 ++++-----
10 files changed, 32 insertions(+), 75 deletions(-)
diff --git a/calc-backend/src/index.ts b/calc-backend/src/index.ts
index 1bf0d6c..548d354 100644
--- a/calc-backend/src/index.ts
+++ b/calc-backend/src/index.ts
@@ -2,7 +2,7 @@ import express from "express";
import cors from "cors";
import routes from "./server.routes";
import errorMiddleware from "./middlewares/errorHandler.middleware";
-import { toNodeHandler, fromNodeHeaders} from "better-auth/node";
+import { toNodeHandler } from "better-auth/node";
import { auth } from "./lib/auth";
const PORT = process.env.PORT || 3000;
@@ -18,13 +18,6 @@ app.use(cors({
app.all("/api/auth/*", toNodeHandler(auth));
-app.get("/api/session", async (req, res) => {
- const session = await auth.api.getSession({
- headers: fromNodeHeaders(req.headers),
- });
- return res.json(session);
-});
-
app.use(express.json()) // use this after better auth
// Prefixes the endpoint with /
diff --git a/calc-backend/src/lib/auth.ts b/calc-backend/src/lib/auth.ts
index 1dfbb8b..4646ea1 100644
--- a/calc-backend/src/lib/auth.ts
+++ b/calc-backend/src/lib/auth.ts
@@ -1,4 +1,4 @@
-import { betterAuth, BetterAuthOptions } from "better-auth";
+import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import prisma from "./prisma";
@@ -29,4 +29,4 @@ export const auth = betterAuth({
},
errorURL: process.env.FRONTEND_URL || 'http://localhost:5173' + '/auth-error'
}
-} satisfies BetterAuthOptions);
+});
diff --git a/calc-frontend/src/App/App.tsx b/calc-frontend/src/App/App.tsx
index a979d71..300e501 100644
--- a/calc-frontend/src/App/App.tsx
+++ b/calc-frontend/src/App/App.tsx
@@ -15,7 +15,8 @@ function App() {
// Handles all the routes
// The calc-visualizer path is for github pages
const router = createBrowserRouter(
- createRoutesFromElements(RoutesList));
+ createRoutesFromElements(RoutesList)
+ );
return (
<>
diff --git a/calc-frontend/src/App/RootLayout.tsx b/calc-frontend/src/App/RootLayout.tsx
index 8019632..bc94d29 100644
--- a/calc-frontend/src/App/RootLayout.tsx
+++ b/calc-frontend/src/App/RootLayout.tsx
@@ -6,34 +6,10 @@ import CalcLogo from "../components/CalcLogo"
import { authClient } from "../lib/auth-client";
import { Avatar, AvatarFallback, AvatarImage } from "../components/ui/avatar"
-import { useEffect } from "react";
-import axios from "axios";
-function RootLayout() {
-
- const serverUrl = import.meta.env.VITE_SERVER_URL || 'http://localhost:3000'
-
- const session = authClient.useSession();
-
-
- const requestSession = async () => {
-
- try{
- const response = await axios.get(serverUrl + '/api/session', { withCredentials: true })
-
- console.log(response)
- }
- catch(e){
- console.error("session error: ", e)
- }
- }
-
- useEffect(() => {
-
- requestSession()
-
- }, [])
+async function RootLayout() {
+ const {data} = await authClient.getSession();
return (
<>
@@ -53,12 +29,12 @@ function RootLayout() {
- {session.data?.session ? (
- session.data?.user.image ? (
+ {data?.session ? (
+ data?.user.image ? (
-
- {session.data?.user.name.charAt(0)}
+
+ {data?.user.name.charAt(0)}
) : (
diff --git a/calc-frontend/src/components/Custom/DerivCustomGraph.tsx b/calc-frontend/src/components/Custom/DerivCustomGraph.tsx
index a835249..33b659a 100644
--- a/calc-frontend/src/components/Custom/DerivCustomGraph.tsx
+++ b/calc-frontend/src/components/Custom/DerivCustomGraph.tsx
@@ -22,7 +22,6 @@ function DerivCustomGraph({func, lowerBound, upperBound, handleSave, onAIRespons
'upperBound': upperBound
}
- // { withCredentials:true}
)
// add loading circle when ready is false
diff --git a/calc-frontend/src/components/Custom/IntCustomGraph.tsx b/calc-frontend/src/components/Custom/IntCustomGraph.tsx
index 6e3bcb0..7b484a2 100644
--- a/calc-frontend/src/components/Custom/IntCustomGraph.tsx
+++ b/calc-frontend/src/components/Custom/IntCustomGraph.tsx
@@ -22,7 +22,6 @@ function IntCustomGraph({func, lowerBound, upperBound, handleSave, onAIResponseC
'upperBound': upperBound
}
- // { withCredentials:true}
)
// add loading circle when ready is false
diff --git a/calc-frontend/src/components/ui/SaveFunctionButton.tsx b/calc-frontend/src/components/ui/SaveFunctionButton.tsx
index 4c462f3..87784cf 100644
--- a/calc-frontend/src/components/ui/SaveFunctionButton.tsx
+++ b/calc-frontend/src/components/ui/SaveFunctionButton.tsx
@@ -1,21 +1,11 @@
-import { useNavigate } from "react-router";
-import { authClient } from "../../lib/auth-client";
-import { Session } from "../../lib/auth-client";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, TooltipArrow } from "@radix-ui/react-tooltip";
-
-function SaveFunctionButton({onSave, saving, enableSave}: {onSave: (session: Session) => void,
+function SaveFunctionButton({onSave, saving, enableSave}: {onSave: () => void,
saving: boolean, enableSave: boolean})
{
- const navigate = useNavigate();
- const session = authClient.useSession();
-
const handleClick = () => {
- if(!session.data?.session ) {
- navigate("/sign-in");
- return;
- }
- onSave(session.data);
+
+ onSave();
}
if(saving){
diff --git a/calc-frontend/src/lib/auth-client.ts b/calc-frontend/src/lib/auth-client.ts
index 1077c4a..01cf185 100644
--- a/calc-frontend/src/lib/auth-client.ts
+++ b/calc-frontend/src/lib/auth-client.ts
@@ -2,6 +2,4 @@ import { createAuthClient } from "better-auth/react"
export const authClient = createAuthClient({
baseURL: import.meta.env.VITE_SERVER_URL || "http://localhost:3000" // the base url of your auth server
-})
-
-export type Session = typeof authClient.$Infer.Session;
\ No newline at end of file
+})
\ No newline at end of file
diff --git a/calc-frontend/src/pages/CustomDerivative.tsx b/calc-frontend/src/pages/CustomDerivative.tsx
index 3e4291a..71c665e 100644
--- a/calc-frontend/src/pages/CustomDerivative.tsx
+++ b/calc-frontend/src/pages/CustomDerivative.tsx
@@ -3,11 +3,11 @@ import { useLocation } from "react-router"
import {generateFunction, validateBounds} from "../functions/mathOutput";
import DerivCustomGraph from "../components/Custom/DerivCustomGraph";
-import { Session } from "../lib/auth-client.ts";
import axios from "axios";
import SaveFunctionButton from "../components/ui/SaveFunctionButton.tsx";
import AskAIButtonDerivative from "@/components/ui/AskAIButtonDerivative.tsx";
import { toast } from "sonner";
+import { authClient } from "../lib/auth-client";
function CustomDeriv() {
@@ -26,6 +26,8 @@ function CustomDeriv() {
state = {func: 'x^2', bounds: [0, 5]}
}
+ const session = authClient.useSession();
+
const container = useRef(null);
const MQ = useRef(null);
const containerMF = useRef(null);
@@ -55,7 +57,7 @@ function CustomDeriv() {
}
// need to check if func is unique first
- const saveFunction = async (session: Session) => {
+ const saveFunction = async () => {
// check if function has been graphed
if(func === ''){
@@ -68,7 +70,7 @@ function CustomDeriv() {
const lowerBound = bounds[0];
const upperBound = bounds[1];
const topic = "Derivative";
- const userId = session.user.id;
+ const userId = session.data?.user.id;
try {
setSaving(true) // show loading while saving
@@ -79,11 +81,10 @@ function CustomDeriv() {
lowerBound,
upperBound,
topic,
- },{
- headers: {
- Authorization: `Bearer ${session.session.token}`
- }
- })
+ },
+ { withCredentials:true}
+ )
+
toast.success("Function Saved Successfully!");
}
catch (error) {
diff --git a/calc-frontend/src/pages/CustomIntegral.tsx b/calc-frontend/src/pages/CustomIntegral.tsx
index 8e8afb2..7e80292 100644
--- a/calc-frontend/src/pages/CustomIntegral.tsx
+++ b/calc-frontend/src/pages/CustomIntegral.tsx
@@ -3,12 +3,12 @@ import { useLocation } from "react-router"
import IntCustomGraph from "../components/Custom/IntCustomGraph.tsx"
import {generateFunction, validateBounds} from "../functions/mathOutput";
-import { Session } from "../lib/auth-client.ts";
import axios from "axios";
import SaveFunctionButton from "../components/ui/SaveFunctionButton.tsx";
import AskAIButton from "../components/ui/AskAIButtonIntegral.tsx";
import { toast } from "sonner";
+import { authClient } from "../lib/auth-client";
function CustomInt() {
@@ -27,6 +27,8 @@ function CustomInt() {
state = {func: 'x^2', bounds: [0, 5]}
}
+ const session = authClient.useSession();
+
const container = useRef(null);
const MQ = useRef(null);
const containerMF = useRef(null);
@@ -57,7 +59,7 @@ function CustomInt() {
}
// need to check if func is unique first
- const saveFunction = async (session: Session) => {
+ const saveFunction = async () => {
// check if function has been graphed
if(func === ''){
@@ -70,7 +72,7 @@ function CustomInt() {
const lowerBound = bounds[0];
const upperBound = bounds[1];
const topic = "Integral";
- const userId = session.user.id;
+ const userId = session.data?.user.id;
try {
setSaving(true) // show loading while saving
@@ -80,11 +82,9 @@ function CustomInt() {
lowerBound,
upperBound,
topic,
- },{
- headers: {
- Authorization: `Bearer ${session.session.token}`
- }
- })
+ },
+ { withCredentials:true}
+ )
toast.success("Function Saved Successfully!");
}
From fcb42092bafd4b5f15aa78eac44a18d632c4a43d Mon Sep 17 00:00:00 2001
From: Anthony Vargas <90121982+Speedrunyourknowledge@users.noreply.github.com>
Date: Sat, 19 Apr 2025 02:43:24 -0400
Subject: [PATCH 03/13] Update README.md
---
README.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/README.md b/README.md
index 86999ef..cc3d426 100644
--- a/README.md
+++ b/README.md
@@ -3,3 +3,7 @@ Calculus visualizer for UCF Knight Hacks. A website with interactive graphs for
## Learn useful git commands
Check out the GIT_COMMANDS.md file. It has all the git commands a beginner (or veteran) should know.
+
+## Make changes here to trigger deployment
+
+change a
From 97f27cf96c3c11ed5fee75e1c14e99b98ed1359f Mon Sep 17 00:00:00 2001
From: Anthony Vargas <90121982+Speedrunyourknowledge@users.noreply.github.com>
Date: Sat, 19 Apr 2025 03:08:38 -0400
Subject: [PATCH 04/13] fix: async function error
---
calc-frontend/src/App/RootLayout.tsx | 30 +++++++++++++++++++++-------
calc-frontend/src/lib/auth-client.ts | 4 +++-
2 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/calc-frontend/src/App/RootLayout.tsx b/calc-frontend/src/App/RootLayout.tsx
index bc94d29..825eb9b 100644
--- a/calc-frontend/src/App/RootLayout.tsx
+++ b/calc-frontend/src/App/RootLayout.tsx
@@ -4,12 +4,28 @@ import { ScrollRestoration } from "react-router";
import ucfLogo from "../assets/ucf-logo.png"
import CalcLogo from "../components/CalcLogo"
-import { authClient } from "../lib/auth-client";
+import { authClient, Session} from "../lib/auth-client";
import { Avatar, AvatarFallback, AvatarImage } from "../components/ui/avatar"
+import { useEffect, useState } from "react";
-async function RootLayout() {
+function RootLayout() {
+
+ const [sessionData, setSessionData] = useState(null)
+
+ const getSession = async () =>{
+
+ const {data} = await authClient.getSession();
+
+ setSessionData(data)
+
+ }
+
+ useEffect(() => {
+
+ getSession()
+
+ },[])
- const {data} = await authClient.getSession();
return (
<>
@@ -29,12 +45,12 @@ async function RootLayout() {
- {data?.session ? (
- data?.user.image ? (
+ {sessionData?.session ? (
+ sessionData.user.image ? (
-
- {data?.user.name.charAt(0)}
+
+ {sessionData.user.name.charAt(0)}
) : (
diff --git a/calc-frontend/src/lib/auth-client.ts b/calc-frontend/src/lib/auth-client.ts
index 01cf185..1077c4a 100644
--- a/calc-frontend/src/lib/auth-client.ts
+++ b/calc-frontend/src/lib/auth-client.ts
@@ -2,4 +2,6 @@ import { createAuthClient } from "better-auth/react"
export const authClient = createAuthClient({
baseURL: import.meta.env.VITE_SERVER_URL || "http://localhost:3000" // the base url of your auth server
-})
\ No newline at end of file
+})
+
+export type Session = typeof authClient.$Infer.Session;
\ No newline at end of file
From ed26b391c320f7d66e1b4de8e4c3d2562c353afb Mon Sep 17 00:00:00 2001
From: Anthony Vargas <90121982+Speedrunyourknowledge@users.noreply.github.com>
Date: Sat, 19 Apr 2025 03:34:55 -0400
Subject: [PATCH 05/13] test: use session and get session
---
calc-frontend/src/App/RootLayout.tsx | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/calc-frontend/src/App/RootLayout.tsx b/calc-frontend/src/App/RootLayout.tsx
index 825eb9b..3ab7fb4 100644
--- a/calc-frontend/src/App/RootLayout.tsx
+++ b/calc-frontend/src/App/RootLayout.tsx
@@ -4,20 +4,20 @@ import { ScrollRestoration } from "react-router";
import ucfLogo from "../assets/ucf-logo.png"
import CalcLogo from "../components/CalcLogo"
-import { authClient, Session} from "../lib/auth-client";
+import { authClient } from "../lib/auth-client";
import { Avatar, AvatarFallback, AvatarImage } from "../components/ui/avatar"
-import { useEffect, useState } from "react";
+import { useEffect } from "react";
function RootLayout() {
- const [sessionData, setSessionData] = useState(null)
+ const session = authClient.useSession();
const getSession = async () =>{
const {data} = await authClient.getSession();
- setSessionData(data)
-
+ console.log('getSession data:' + data)
+ console.log('useSession: ' + session)
}
useEffect(() => {
@@ -45,12 +45,12 @@ function RootLayout() {
- {sessionData?.session ? (
- sessionData.user.image ? (
+ {session.data?.session ? (
+ session.data.user.image ? (
-
- {sessionData.user.name.charAt(0)}
+
+ {session.data.user.name.charAt(0)}
) : (
From 99241d947760a7c208212407f1923b6769536a21 Mon Sep 17 00:00:00 2001
From: Anthony Vargas <90121982+Speedrunyourknowledge@users.noreply.github.com>
Date: Sat, 19 Apr 2025 05:09:27 -0400
Subject: [PATCH 06/13] fix: cors subdomain
---
calc-backend/src/lib/auth.ts | 16 ++++++++++++++--
calc-frontend/src/App/RootLayout.tsx | 17 ++---------------
2 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/calc-backend/src/lib/auth.ts b/calc-backend/src/lib/auth.ts
index 4646ea1..d074cd5 100644
--- a/calc-backend/src/lib/auth.ts
+++ b/calc-backend/src/lib/auth.ts
@@ -6,7 +6,9 @@ export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: "mongodb",
}),
- trustedOrigins: ["http://localhost:5173", 'https://calcvisualizer.netlify.app'],
+ trustedOrigins: ["http://localhost:5173",
+ "calcvisualizer.speedrunyourknowledge.com",
+ ],
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID as string,
@@ -20,7 +22,17 @@ export const auth = betterAuth({
}
},
advanced: {
- cookiePrefix: "calcvis"
+ cookiePrefix: "calcvis",
+ crossSubDomainCookies: {
+ enabled: true,
+ domain: ".speedrunyourknowledge.com", // Domain with a leading period
+ },
+ defaultCookieAttributes: {
+ secure: true,
+ httpOnly: true,
+ sameSite: "none", // Allows CORS-based cookie sharing across subdomains
+ partitioned: true, // New browser standards will mandate this for foreign cookies
+ },
},
onAPIError: {
throw: true,
diff --git a/calc-frontend/src/App/RootLayout.tsx b/calc-frontend/src/App/RootLayout.tsx
index 3ab7fb4..de9eacb 100644
--- a/calc-frontend/src/App/RootLayout.tsx
+++ b/calc-frontend/src/App/RootLayout.tsx
@@ -6,26 +6,13 @@ import CalcLogo from "../components/CalcLogo"
import { authClient } from "../lib/auth-client";
import { Avatar, AvatarFallback, AvatarImage } from "../components/ui/avatar"
-import { useEffect } from "react";
function RootLayout() {
const session = authClient.useSession();
- const getSession = async () =>{
-
- const {data} = await authClient.getSession();
-
- console.log('getSession data:' + data)
- console.log('useSession: ' + session)
- }
-
- useEffect(() => {
-
- getSession()
-
- },[])
-
+ console.log('useSession: ' + session)
+
return (
<>
From d23f04b2defa315d7f2a59229d673516f7dcdb71 Mon Sep 17 00:00:00 2001
From: Anthony Vargas <90121982+Speedrunyourknowledge@users.noreply.github.com>
Date: Sat, 19 Apr 2025 05:13:32 -0400
Subject: [PATCH 07/13] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index cc3d426..7da79f3 100644
--- a/README.md
+++ b/README.md
@@ -6,4 +6,4 @@ Check out the GIT_COMMANDS.md file. It has all the git commands a beginner (or v
## Make changes here to trigger deployment
-change a
+change b
From e7ca102a64e3d45e665e209d4c29184347eeb4f7 Mon Sep 17 00:00:00 2001
From: Anthony Vargas <90121982+Speedrunyourknowledge@users.noreply.github.com>
Date: Sat, 19 Apr 2025 05:20:29 -0400
Subject: [PATCH 08/13] fix: typo in url
---
calc-backend/src/lib/auth.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/calc-backend/src/lib/auth.ts b/calc-backend/src/lib/auth.ts
index d074cd5..1665ff7 100644
--- a/calc-backend/src/lib/auth.ts
+++ b/calc-backend/src/lib/auth.ts
@@ -7,7 +7,7 @@ export const auth = betterAuth({
provider: "mongodb",
}),
trustedOrigins: ["http://localhost:5173",
- "calcvisualizer.speedrunyourknowledge.com",
+ "https://calcvisualizer.speedrunyourknowledge.com",
],
socialProviders: {
google: {
From f7f48e7b321a6d461109abe32e628b71ce822ce9 Mon Sep 17 00:00:00 2001
From: Anthony Vargas <90121982+Speedrunyourknowledge@users.noreply.github.com>
Date: Sat, 19 Apr 2025 09:18:31 -0400
Subject: [PATCH 09/13] fix: add back netlify url to trusted origins
---
calc-backend/src/lib/auth.ts | 1 +
1 file changed, 1 insertion(+)
diff --git a/calc-backend/src/lib/auth.ts b/calc-backend/src/lib/auth.ts
index 1665ff7..c3252be 100644
--- a/calc-backend/src/lib/auth.ts
+++ b/calc-backend/src/lib/auth.ts
@@ -8,6 +8,7 @@ export const auth = betterAuth({
}),
trustedOrigins: ["http://localhost:5173",
"https://calcvisualizer.speedrunyourknowledge.com",
+ "https://calcvisualizer.netlify.app"
],
socialProviders: {
google: {
From e84f96c80c62953ccb68fe0af94298bfc8e3e5aa Mon Sep 17 00:00:00 2001
From: Anthony Vargas <90121982+Speedrunyourknowledge@users.noreply.github.com>
Date: Sat, 19 Apr 2025 09:31:19 -0400
Subject: [PATCH 10/13] fix: try clearing cookie cache
---
calc-backend/src/lib/auth.ts | 6 ------
calc-frontend/src/lib/auth-client.ts | 3 ++-
2 files changed, 2 insertions(+), 7 deletions(-)
diff --git a/calc-backend/src/lib/auth.ts b/calc-backend/src/lib/auth.ts
index c3252be..e9415e7 100644
--- a/calc-backend/src/lib/auth.ts
+++ b/calc-backend/src/lib/auth.ts
@@ -16,12 +16,6 @@ export const auth = betterAuth({
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
}
},
- session: {
- cookieCache: {
- enabled: true,
- maxAge: 60 * 60 // Cache duration in seconds
- }
- },
advanced: {
cookiePrefix: "calcvis",
crossSubDomainCookies: {
diff --git a/calc-frontend/src/lib/auth-client.ts b/calc-frontend/src/lib/auth-client.ts
index 1077c4a..ddc85e0 100644
--- a/calc-frontend/src/lib/auth-client.ts
+++ b/calc-frontend/src/lib/auth-client.ts
@@ -1,7 +1,8 @@
import { createAuthClient } from "better-auth/react"
export const authClient = createAuthClient({
- baseURL: import.meta.env.VITE_SERVER_URL || "http://localhost:3000" // the base url of your auth server
+ baseURL: import.meta.env.VITE_SERVER_URL || "http://localhost:3000", // the base url of your auth server
+ redirect:false
})
export type Session = typeof authClient.$Infer.Session;
\ No newline at end of file
From 689c4c4d4d4d5bf5d7d63be8ad86c39c36809e05 Mon Sep 17 00:00:00 2001
From: Anthony Vargas <90121982+Speedrunyourknowledge@users.noreply.github.com>
Date: Sat, 19 Apr 2025 09:43:28 -0400
Subject: [PATCH 11/13] test: change auth client options
---
calc-frontend/src/lib/auth-client.ts | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/calc-frontend/src/lib/auth-client.ts b/calc-frontend/src/lib/auth-client.ts
index ddc85e0..1077c4a 100644
--- a/calc-frontend/src/lib/auth-client.ts
+++ b/calc-frontend/src/lib/auth-client.ts
@@ -1,8 +1,7 @@
import { createAuthClient } from "better-auth/react"
export const authClient = createAuthClient({
- baseURL: import.meta.env.VITE_SERVER_URL || "http://localhost:3000", // the base url of your auth server
- redirect:false
+ baseURL: import.meta.env.VITE_SERVER_URL || "http://localhost:3000" // the base url of your auth server
})
export type Session = typeof authClient.$Infer.Session;
\ No newline at end of file
From 8837b45c9dc46bb8fc3937fbf015ce6a10cceb91 Mon Sep 17 00:00:00 2001
From: Anthony Vargas <90121982+Speedrunyourknowledge@users.noreply.github.com>
Date: Sat, 19 Apr 2025 11:01:46 -0400
Subject: [PATCH 12/13] test: sign out button options
---
calc-frontend/src/App/RootLayout.tsx | 3 +--
.../src/components/ui/SignOutButton.tsx | 17 ++++++++++++-----
calc-frontend/src/pages/Home.tsx | 2 +-
3 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/calc-frontend/src/App/RootLayout.tsx b/calc-frontend/src/App/RootLayout.tsx
index de9eacb..84c7621 100644
--- a/calc-frontend/src/App/RootLayout.tsx
+++ b/calc-frontend/src/App/RootLayout.tsx
@@ -11,9 +11,8 @@ function RootLayout() {
const session = authClient.useSession();
- console.log('useSession: ' + session)
+ console.log('useSession: ' + session.data)
-
return (
<>
diff --git a/calc-frontend/src/components/ui/SignOutButton.tsx b/calc-frontend/src/components/ui/SignOutButton.tsx
index 91e9376..85eb445 100644
--- a/calc-frontend/src/components/ui/SignOutButton.tsx
+++ b/calc-frontend/src/components/ui/SignOutButton.tsx
@@ -1,15 +1,22 @@
-import { toast } from "sonner";
import { authClient } from "../../lib/auth-client"
+import { useNavigate } from "react-router";
function SignOutButton()
{
+ const navigate = useNavigate()
+
const handleSignOut = async () => {
try {
- await authClient.signOut();
-
+ await authClient.signOut({
+ fetchOptions: {
+ onSuccess: () => {
+ navigate("/"); // redirect to home
+ },
+ withCredentials:true
+ }
+ });
} catch (error) {
- toast.error("Something went wrong signing out");
- console.error("Error signing out:", error);
+ console.error("Error signing out: ", error);
}
}
diff --git a/calc-frontend/src/pages/Home.tsx b/calc-frontend/src/pages/Home.tsx
index 4a25dca..47194bd 100644
--- a/calc-frontend/src/pages/Home.tsx
+++ b/calc-frontend/src/pages/Home.tsx
@@ -81,7 +81,7 @@ function Home() {
{session.isPending === true?
null
:
- !session.data?.session ? :
+ session.data?.session ? :
}
From d31814b5dc41adf3deacea8d4135a0eda40038cb Mon Sep 17 00:00:00 2001
From: Anthony Vargas <90121982+Speedrunyourknowledge@users.noreply.github.com>
Date: Sat, 19 Apr 2025 11:10:24 -0400
Subject: [PATCH 13/13] fix: remove cookie prefex which caused mismatch
---
calc-backend/src/lib/auth.ts | 1 -
1 file changed, 1 deletion(-)
diff --git a/calc-backend/src/lib/auth.ts b/calc-backend/src/lib/auth.ts
index e9415e7..f95d29f 100644
--- a/calc-backend/src/lib/auth.ts
+++ b/calc-backend/src/lib/auth.ts
@@ -17,7 +17,6 @@ export const auth = betterAuth({
}
},
advanced: {
- cookiePrefix: "calcvis",
crossSubDomainCookies: {
enabled: true,
domain: ".speedrunyourknowledge.com", // Domain with a leading period