Skip to content

Commit d545667

Browse files
Merge pull request #205 from Speedrunyourknowledge/develop
fix: sign-in now works on the internet
2 parents 9811479 + a275b85 commit d545667

File tree

13 files changed

+70
-92
lines changed

13 files changed

+70
-92
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ Calculus visualizer for UCF Knight Hacks. A website with interactive graphs for
33

44
## Learn useful git commands
55
Check out the GIT_COMMANDS.md file. It has all the git commands a beginner (or veteran) should know.
6+
7+
## Make changes here to trigger deployment
8+
9+
change b

calc-backend/prisma/schema.prisma

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
generator client {
88
provider = "prisma-client-js"
9-
output = "./client"
9+
output = "./client"
1010
}
1111

1212
datasource db {
@@ -65,14 +65,14 @@ model Account {
6565
}
6666

6767
model Verification {
68-
id String @id @default(cuid()) @map("_id")
69-
identifier String
70-
value String
71-
expiresAt DateTime
72-
createdAt DateTime @default(now())
73-
updatedAt DateTime @updatedAt
74-
75-
@@map("verification")
68+
id String @id @default(cuid()) @map("_id")
69+
identifier String
70+
value String
71+
expiresAt DateTime
72+
createdAt DateTime @default(now())
73+
updatedAt DateTime @updatedAt
74+
75+
@@map("verification")
7676
}
7777

7878
model Func {

calc-backend/src/index.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import express from "express";
22
import cors from "cors";
33
import routes from "./server.routes";
44
import errorMiddleware from "./middlewares/errorHandler.middleware";
5-
import { toNodeHandler, fromNodeHeaders} from "better-auth/node";
5+
import { toNodeHandler } from "better-auth/node";
66
import { auth } from "./lib/auth";
77

88
const PORT = process.env.PORT || 3000;
@@ -18,13 +18,6 @@ app.use(cors({
1818

1919
app.all("/api/auth/*", toNodeHandler(auth));
2020

21-
app.get("/api/session", async (req, res) => {
22-
const session = await auth.api.getSession({
23-
headers: fromNodeHeaders(req.headers),
24-
});
25-
return res.json(session);
26-
});
27-
2821
app.use(express.json()) // use this after better auth
2922

3023
// Prefixes the endpoint with /

calc-backend/src/lib/auth.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
1-
import { betterAuth, BetterAuthOptions } from "better-auth";
1+
import { betterAuth } from "better-auth";
22
import { prismaAdapter } from "better-auth/adapters/prisma";
33
import prisma from "./prisma";
44

55
export const auth = betterAuth({
66
database: prismaAdapter(prisma, {
77
provider: "mongodb",
88
}),
9-
trustedOrigins: ["http://localhost:5173", 'https://calcvisualizer.netlify.app'],
9+
trustedOrigins: ["http://localhost:5173",
10+
"https://calcvisualizer.speedrunyourknowledge.com",
11+
"https://calcvisualizer.netlify.app"
12+
],
1013
socialProviders: {
1114
google: {
1215
clientId: process.env.GOOGLE_CLIENT_ID as string,
1316
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
1417
}
1518
},
16-
session: {
17-
cookieCache: {
18-
enabled: true,
19-
maxAge: 60 * 60 // Cache duration in seconds
20-
}
21-
},
2219
advanced: {
23-
cookiePrefix: "calcvis"
20+
crossSubDomainCookies: {
21+
enabled: true,
22+
domain: ".speedrunyourknowledge.com", // Domain with a leading period
23+
},
24+
defaultCookieAttributes: {
25+
secure: true,
26+
httpOnly: true,
27+
sameSite: "none", // Allows CORS-based cookie sharing across subdomains
28+
partitioned: true, // New browser standards will mandate this for foreign cookies
29+
},
2430
},
2531
onAPIError: {
2632
throw: true,
@@ -29,4 +35,4 @@ export const auth = betterAuth({
2935
},
3036
errorURL: process.env.FRONTEND_URL || 'http://localhost:5173' + '/auth-error'
3137
}
32-
} satisfies BetterAuthOptions);
38+
});

calc-frontend/src/App/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ function App() {
1515
// Handles all the routes
1616
// The calc-visualizer path is for github pages
1717
const router = createBrowserRouter(
18-
createRoutesFromElements(RoutesList));
18+
createRoutesFromElements(RoutesList)
19+
);
1920

2021
return (
2122
<>

calc-frontend/src/App/RootLayout.tsx

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,13 @@ import CalcLogo from "../components/CalcLogo"
66

77
import { authClient } from "../lib/auth-client";
88
import { Avatar, AvatarFallback, AvatarImage } from "../components/ui/avatar"
9-
import { useEffect } from "react";
10-
import axios from "axios";
119

1210
function RootLayout() {
1311

14-
const serverUrl = import.meta.env.VITE_SERVER_URL || 'http://localhost:3000'
15-
1612
const session = authClient.useSession();
1713

18-
19-
const requestSession = async () => {
20-
21-
try{
22-
const response = await axios.get(serverUrl + '/api/session', { withCredentials: true })
23-
24-
console.log(response)
25-
}
26-
catch(e){
27-
console.error("session error: ", e)
28-
}
29-
}
30-
31-
useEffect(() => {
32-
33-
requestSession()
34-
35-
}, [])
36-
37-
14+
console.log('useSession: ' + session.data)
15+
3816
return (
3917
<>
4018
<ScrollRestoration />
@@ -54,11 +32,11 @@ function RootLayout() {
5432

5533
</div>
5634
{session.data?.session ? (
57-
session.data?.user.image ? (
35+
session.data.user.image ? (
5836
<Link to="/dashboard">
5937
<Avatar className="mr-5 cursor-pointer w-12 h-12">
60-
<AvatarImage src={session.data?.user.image} />
61-
<AvatarFallback>{session.data?.user.name.charAt(0)}</AvatarFallback>
38+
<AvatarImage src={session.data.user.image} />
39+
<AvatarFallback>{session.data.user.name.charAt(0)}</AvatarFallback>
6240
</Avatar>
6341
</Link>
6442
) : (

calc-frontend/src/components/Custom/DerivCustomGraph.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ function DerivCustomGraph({func, lowerBound, upperBound, handleSave, onAIRespons
2222
'upperBound': upperBound
2323

2424
}
25-
// { withCredentials:true}
2625
)
2726

2827
// add loading circle when ready is false

calc-frontend/src/components/Custom/IntCustomGraph.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ function IntCustomGraph({func, lowerBound, upperBound, handleSave, onAIResponseC
2222
'upperBound': upperBound
2323

2424
}
25-
// { withCredentials:true}
2625
)
2726

2827
// add loading circle when ready is false

calc-frontend/src/components/ui/SaveFunctionButton.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
import { useNavigate } from "react-router";
2-
import { authClient } from "../../lib/auth-client";
3-
import { Session } from "../../lib/auth-client";
41
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, TooltipArrow } from "@radix-ui/react-tooltip";
52

6-
7-
function SaveFunctionButton({onSave, saving, enableSave}: {onSave: (session: Session) => void,
3+
function SaveFunctionButton({onSave, saving, enableSave}: {onSave: () => void,
84
saving: boolean, enableSave: boolean})
95
{
10-
const navigate = useNavigate();
11-
const session = authClient.useSession();
12-
136
const handleClick = () => {
14-
if(!session.data?.session ) {
15-
navigate("/sign-in");
16-
return;
17-
}
18-
onSave(session.data);
7+
8+
onSave();
199
}
2010

2111
if(saving){

calc-frontend/src/components/ui/SignOutButton.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
import { toast } from "sonner";
21
import { authClient } from "../../lib/auth-client"
2+
import { useNavigate } from "react-router";
33

44
function SignOutButton()
55
{
6+
const navigate = useNavigate()
7+
68
const handleSignOut = async () => {
79
try {
8-
await authClient.signOut();
9-
10+
await authClient.signOut({
11+
fetchOptions: {
12+
onSuccess: () => {
13+
navigate("/"); // redirect to home
14+
},
15+
withCredentials:true
16+
}
17+
});
1018
} catch (error) {
11-
toast.error("Something went wrong signing out");
12-
console.error("Error signing out:", error);
19+
console.error("Error signing out: ", error);
1320
}
1421
}
1522

0 commit comments

Comments
 (0)