Skip to content

Commit bf3de11

Browse files
Merge pull request #199 from Speedrunyourknowledge/develop
fix: get session from server this time
2 parents fecfc0b + b7ba535 commit bf3de11

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

calc-backend/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ app.use(cors({
1818

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

21-
/*
2221
app.get("/api/session", async (req, res) => {
2322
const session = await auth.api.getSession({
2423
headers: fromNodeHeaders(req.headers),
2524
});
2625
return res.json(session);
2726
});
28-
*/
2927

3028
app.use(express.json()) // use this after better auth
3129

calc-frontend/src/App/RootLayout.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,34 @@ import CalcLogo from "../components/CalcLogo"
66

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

1112
function RootLayout() {
1213

13-
const oldSession = authClient.useSession();
14+
const serverUrl = import.meta.env.VITE_SERVER_URL || 'http://localhost:3000'
1415

15-
const [session, setSession] = useState(oldSession)
16+
const session = authClient.useSession();
1617

17-
// function to get the session
18-
const initializeSession = async() => {
19-
await authClient.getSession(); // getting session value
2018

21-
const newSession = authClient.useSession()
22-
23-
setSession(newSession);
19+
const requestSession = async () => {
20+
21+
try{
22+
const response = await axios.get(serverUrl + '/api/session')
23+
24+
console.log(response)
25+
}
26+
catch(e){
27+
console.error("session error: ", e)
28+
}
2429
}
2530

26-
initializeSession()
31+
useEffect(() => {
32+
33+
requestSession()
34+
35+
}, [])
36+
2737

2838
return (
2939
<>

0 commit comments

Comments
 (0)