-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.tsx
47 lines (39 loc) · 1.9 KB
/
app.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import React, { useState, useEffect } from 'react';
import * as ReactDOM from 'react-dom'
import { query, initThinBackend, DataSubscription, createRecord, updateRecord, deleteRecord, createRecords, ensureIsUser, logout, getCurrentUserId } from 'thin-backend';
import { useQuery, useCurrentUser, ThinBackend } from 'thin-backend-react';
import 'thin-backend-react/auth.css';
function App() {
// With `useQuery()` you can access your database:
//
// const todos = useQuery(query('todos').orderBy('createdAt'));
return <ThinBackend requireLogin>
<div className="container">
<AppNavbar/>
</div>
</ThinBackend>
}
function AppNavbar() {
// Use the `useCurrentUser()` react hook to access the current logged in user
const user = useCurrentUser();
// This navbar requires bootstrap js helpers for the dropdown
// If the dropdown is not working, you like removed the bootstrap JS from your index.html
return <nav className="navbar navbar-expand-lg navbar-light bg-light mb-5">
<div className="collapse navbar-collapse" id="navbarSupportedContent">
<ul className="navbar-nav ml-auto">
<li className="nav-item dropdown">
<a className="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{user?.email}
</a>
<div className="dropdown-menu" aria-labelledby="navbarDropdown">
<a className="dropdown-item" href="#" onClick={() => logout()}>Logout</a>
</div>
</li>
</ul>
</div>
</nav>
}
// This needs to be run before any calls to `query`, `createRecord`, etc.
initThinBackend({ host: process.env.BACKEND_URL });
// Start the React app
ReactDOM.render(<App/>, document.getElementById('app'));