feat: UserRequired
This commit is contained in:
parent
60c844d58b
commit
9b5f6f4818
|
@ -23,8 +23,8 @@
|
|||
"client.js.map",
|
||||
"index.js",
|
||||
"index.js.map",
|
||||
"local/client.js",
|
||||
"local/client.js.map",
|
||||
"local.js",
|
||||
"local.js.map",
|
||||
"local/server.js",
|
||||
"local/server.js.map",
|
||||
"server.js",
|
||||
|
|
|
@ -2,11 +2,9 @@ import {Hooks} from '@flecks/core';
|
|||
|
||||
import {Logout} from './packets';
|
||||
|
||||
import user from './state/user';
|
||||
import users from './state/users';
|
||||
import {user, users} from './state';
|
||||
|
||||
export * from './state/user';
|
||||
export * from './state/users';
|
||||
export * from './state';
|
||||
|
||||
export default {
|
||||
[Hooks]: {
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
import {React} from '@flecks/react';
|
||||
|
||||
const UserLocalLogin = () => (
|
||||
<form action="/auth/local" method="post">
|
||||
<label>
|
||||
<span>Email address</span>
|
||||
<input autoComplete="username" name="email" type="text" />
|
||||
</label>
|
||||
<label>
|
||||
<span>Password</span>
|
||||
<input autoComplete="current-password" name="password" type="password" />
|
||||
</label>
|
||||
<div>
|
||||
<label>
|
||||
<input type="checkbox" />
|
||||
<span>Remember me</span>
|
||||
</label>
|
||||
<a href="/auth/forgot">Forgot password?</a>
|
||||
</div>
|
||||
<label>
|
||||
<input type="submit" value="Sign in" />
|
||||
</label>
|
||||
</form>
|
||||
);
|
||||
|
||||
export default UserLocalLogin;
|
|
@ -1,2 +1,2 @@
|
|||
// eslint-disable-next-line import/prefer-default-export
|
||||
export {default as UserLocalLogin} from './user-local-login';
|
||||
export {default as UserRequired} from './user-required';
|
28
packages/user/src/local/components/user-local-login.jsx
Normal file
28
packages/user/src/local/components/user-local-login.jsx
Normal file
|
@ -0,0 +1,28 @@
|
|||
import {React} from '@flecks/react';
|
||||
|
||||
function UserLocalLogin() {
|
||||
return (
|
||||
<form action="/auth/local" method="post">
|
||||
<label>
|
||||
<span>Email address</span>
|
||||
<input autoComplete="username" name="email" type="text" />
|
||||
</label>
|
||||
<label>
|
||||
<span>Password</span>
|
||||
<input autoComplete="current-password" name="password" type="password" />
|
||||
</label>
|
||||
<div>
|
||||
<label>
|
||||
<input type="checkbox" />
|
||||
<span>Remember me</span>
|
||||
</label>
|
||||
<a href="/auth/forgot">Forgot password?</a>
|
||||
</div>
|
||||
<label>
|
||||
<input type="submit" value="Sign in" />
|
||||
</label>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
export default UserLocalLogin;
|
26
packages/user/src/local/components/user-required.jsx
Normal file
26
packages/user/src/local/components/user-required.jsx
Normal file
|
@ -0,0 +1,26 @@
|
|||
import {PropTypes, React} from '@flecks/react';
|
||||
import {Navigate, useLocation} from '@flecks/react/router';
|
||||
import {useSelector} from '@flecks/redux';
|
||||
import {userIdSelector} from '@flecks/user/state';
|
||||
|
||||
function UserRequired({children, destination}) {
|
||||
const location = useLocation();
|
||||
const userId = useSelector(userIdSelector);
|
||||
if (0 === userId) {
|
||||
return <Navigate to={destination} state={{from: location}} replace />;
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
UserRequired.defaultProps = {
|
||||
destination: '/login',
|
||||
};
|
||||
|
||||
UserRequired.displayName = 'UserRequired';
|
||||
|
||||
UserRequired.propTypes = {
|
||||
children: PropTypes.node.isRequired,
|
||||
destination: PropTypes.string,
|
||||
};
|
||||
|
||||
export default UserRequired;
|
5
packages/user/src/state/index.js
Normal file
5
packages/user/src/state/index.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
export * from './user';
|
||||
export {default as user} from './user';
|
||||
|
||||
export * from './users';
|
||||
export {default as users} from './users';
|
Loading…
Reference in New Issue
Block a user