add_user_conv impl

This commit is contained in:
2025-12-29 17:22:38 +01:00
parent 8af10eb381
commit 39867c2c36
6 changed files with 245 additions and 33 deletions

View File

@@ -1,4 +1,5 @@
import { useState, useEffect } from 'react'
import { createContext } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'
@@ -8,15 +9,20 @@ import { API_BASE } from './config.js'
import Login from './components/login.jsx'
import MainApp from './components/MainApp.jsx'
export const ClientContext = createContext(null);
export function userContext() {}
export default function App() {
const [loading, setLoading] = useState(true); // true while checking auth
const [loggedIn, setLoggedIn] = useState(false);
const [clientId, setClientId] = useState([]);
useEffect(() => {
async function checkAuth() {
try {
// This endpoint should validate the refresh token cookie and return an access token
const res = await fetch(`${API_BASE}/auth/login_refresh_token`, {
method: "POST",
headers: {
@@ -28,7 +34,9 @@ export default function App() {
device_id : "147ac10b-58cc-4372-a567-0e02b2c3d479", // or persistent device ID
}),
});
console.log("sent checkAuth request")
if (!res.ok) {
console.log(res)
console.log("checkAuth request not ok")
@@ -40,6 +48,8 @@ export default function App() {
const data = await res.json();
console.log(data)
localStorage.setItem("access_tokens", JSON.stringify(data.tokens)); // store for API calls
setClientId(data.user_id)
setLoggedIn(true);
}
} catch (err) {
@@ -57,7 +67,7 @@ export default function App() {
// Show main app if logged in, otherwise show login
return loggedIn ? (
<MainApp />
<MainApp resClientId ={clientId} />
) : (
<Login onLogin={() => setLoggedIn(true)} />
);