profile section to allow token generation
This commit is contained in:
parent
fe259886a3
commit
53c6f6448c
@ -8,6 +8,7 @@ import Media from './pages/Media';
|
|||||||
import LoginPage from './pages/Login';
|
import LoginPage from './pages/Login';
|
||||||
import Panel from './pages/Panel';
|
import Panel from './pages/Panel';
|
||||||
import Mobile from './pages/Mobile';
|
import Mobile from './pages/Mobile';
|
||||||
|
import Profile from './pages/Profile';
|
||||||
import { clearSession, fetchUser, setSession, logout } from './util/Util';
|
import { clearSession, fetchUser, setSession, logout } from './util/Util';
|
||||||
import { PrivateRoute } from './Routes/Private';
|
import { PrivateRoute } from './Routes/Private';
|
||||||
import { useLoginContext } from './Structures/UserContext';
|
import { useLoginContext } from './Structures/UserContext';
|
||||||
@ -17,7 +18,8 @@ import Upload from './pages/Upload';
|
|||||||
const User = ({user}) => {
|
const User = ({user}) => {
|
||||||
return (
|
return (
|
||||||
<div className='flex-container user-controls'>
|
<div className='flex-container user-controls'>
|
||||||
<p className='no-margin'> {user.tag} </p>
|
<p className='no-margin'> </p>
|
||||||
|
<NavLink className='navlink' to='/profile' >{user.tag}</NavLink>
|
||||||
<button className='logout-btn' onClick={logout}>Logout</button>
|
<button className='logout-btn' onClick={logout}>Logout</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@ -104,6 +106,7 @@ function App() {
|
|||||||
<Route exact path='/login' element={<LoginPage />} />
|
<Route exact path='/login' element={<LoginPage />} />
|
||||||
<Route path='/upload' element={<PrivateRoute><Upload /></PrivateRoute>} />
|
<Route path='/upload' element={<PrivateRoute><Upload /></PrivateRoute>} />
|
||||||
<Route path='/panel' element={<PrivateRoute><Panel /></PrivateRoute>} />
|
<Route path='/panel' element={<PrivateRoute><Panel /></PrivateRoute>} />
|
||||||
|
<Route path='/profile' element={<PrivateRoute><Profile /></PrivateRoute>} />
|
||||||
<Route path='*' element={<NotFound />} />
|
<Route path='*' element={<NotFound />} />
|
||||||
|
|
||||||
</Routes>
|
</Routes>
|
||||||
|
11
client/src/css/Profile.css
Normal file
11
client/src/css/Profile.css
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
.profile {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.token {
|
||||||
|
background-color: gray;
|
||||||
|
position: relative;
|
||||||
|
top: 2vh;
|
||||||
|
margin: auto;
|
||||||
|
width: 50%;
|
||||||
|
}
|
@ -82,3 +82,10 @@ code {
|
|||||||
a {
|
a {
|
||||||
color: var(--navy-blue);
|
color: var(--navy-blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
background-color: #7777778c;
|
||||||
|
border-radius: 4px;
|
||||||
|
padding-left: 4px;
|
||||||
|
padding-right: 4px;
|
||||||
|
}
|
60
client/src/pages/Profile.js
Normal file
60
client/src/pages/Profile.js
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import React, { useState } from "react";
|
||||||
|
import { useLoginContext } from "../Structures/UserContext";
|
||||||
|
import '../css/Profile.css';
|
||||||
|
|
||||||
|
const Token = ({ user }) => {
|
||||||
|
|
||||||
|
const [token, updateToken] = useState(user?.token);
|
||||||
|
console.log(user);
|
||||||
|
|
||||||
|
const generateToken = async ({target: button}) => {
|
||||||
|
|
||||||
|
button.disabled = true;
|
||||||
|
const response = await fetch(`/api/user/token`, {
|
||||||
|
credentials: 'include'
|
||||||
|
});
|
||||||
|
|
||||||
|
button.disabled = true;
|
||||||
|
|
||||||
|
if (response.status !== 200) return;
|
||||||
|
|
||||||
|
const { token } = await response.json();
|
||||||
|
updateToken(token);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div >
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The upload token lets you send files directly to the <code>/api/upload</code> endpoint.<br />
|
||||||
|
The token needs to be under the <code>Authorization</code> header.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className='token'>
|
||||||
|
{!token ?
|
||||||
|
<span><button onClick={generateToken}>Generate token</button> </span> :
|
||||||
|
<span><p>{token}</p> <button onClick={generateToken}>Regenerate token</button></span>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const Profile = () => {
|
||||||
|
|
||||||
|
const [user] = useLoginContext();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='profile'>
|
||||||
|
|
||||||
|
<Token user={user} />
|
||||||
|
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Profile;
|
@ -56,6 +56,7 @@ const Upload = () => {
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input
|
<input
|
||||||
|
autoFocus
|
||||||
id='name'
|
id='name'
|
||||||
type='text'
|
type='text'
|
||||||
onChange={event => updateName(event.target.value)}
|
onChange={event => updateName(event.target.value)}
|
||||||
|
Loading…
Reference in New Issue
Block a user