Skip to content

Commit

Permalink
use client from pocketbase localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
aleda145 committed Aug 2, 2022
1 parent 33d6f74 commit d4d9bb3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
11 changes: 8 additions & 3 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@ import Auth from "./auth/pocketbase";
import { BrowserRouter, Routes, Route } from "react-router-dom";
import Dashboard from "./Dashboard/Dashboard";
import Preferences from "./Preferences/Preferences";
import PocketBase from "pocketbase";

function App() {
const [token, setToken] = useState();
console.log(token);
if (!token) {
return <Auth setToken={setToken} />;
const client = new PocketBase("http://localhost:8090");
console.log(client.AuthStore.isValid);
console.log(client.AuthStore.model.email);
if (!client.AuthStore.isValid) {
return <Auth client={client} />;
}
return (
<div className="wrapper">
<h1>Application</h1>
<BrowserRouter>
<Routes>
{/* <Route path="/" element={<App />} /> */}
<Route path="dashboard" element={<Dashboard />} />
<Route path="dashboard" element={<Dashboard client={client} />} />
<Route path="preferences" element={<Preferences />} />
</Routes>
</BrowserRouter>
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/Dashboard/Dashboard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";

export default function Dashboard() {
return <h2>Dashboard</h2>;
export default function Dashboard({ client }) {
console.log(client);
return <h2>Dashboard {client.AuthStore.model.email}</h2>;
}
12 changes: 2 additions & 10 deletions frontend/src/auth/pocketbase.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import React, { useState } from "react";
import PocketBase from "pocketbase";
import PropTypes from "prop-types";
// const client = new PocketBase("http://localhost:8090");

// const userData = client.Users.authViaEmail("[email protected]", "12345678");
// console.log(userData);

export default function Auth({ setToken }) {
export default function Auth({ client }) {
const [username, setUserName] = useState();
const [password, setPassword] = useState();

const handleSubmit = async (e) => {
const client = new PocketBase("http://localhost:8090");
e.preventDefault();
const userData = await client.Users.authViaEmail(username, password);
console.log(userData);
setToken(userData.token);
};
return (
<div className="login-wrapper">
Expand All @@ -41,5 +33,5 @@ export default function Auth({ setToken }) {
}

Auth.propTypes = {
setToken: PropTypes.func.isRequired,
client: PropTypes.any.isRequired,
};

0 comments on commit d4d9bb3

Please sign in to comment.