aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/ui
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2024-02-09 19:10:01 +0300
committerGravatar Vitaly Takmazov2024-02-09 19:13:28 +0300
commit9e01a8d3c3daf3257f29ad63b3836dfa89c6200b (patch)
treefc785536ffd05a2232da5222f55e9a5268f99f32 /vnext/src/ui
parente2674c3b27174e408264b84f50bf86a13e2d3824 (diff)
vnext: authorize on backend
Diffstat (limited to 'vnext/src/ui')
-rw-r--r--vnext/src/ui/Feeds.js2
-rw-r--r--vnext/src/ui/Login.js88
-rw-r--r--vnext/src/ui/Message.js4
3 files changed, 3 insertions, 91 deletions
diff --git a/vnext/src/ui/Feeds.js b/vnext/src/ui/Feeds.js
index 16b6b534..0cebdce6 100644
--- a/vnext/src/ui/Feeds.js
+++ b/vnext/src/ui/Feeds.js
@@ -35,7 +35,7 @@ function RequireAuth({ children }) {
// trying to go to when they were redirected. This allows us to send them
// along to that page after they login, which is a nicer user experience
// than dropping them off on the home page.
- return <Navigate to="/login" state={{ from: location }} />
+ return <Navigate to={`/login?retpath=${window.location.href}`} state={{ from: location }} />
}
return children
diff --git a/vnext/src/ui/Login.js b/vnext/src/ui/Login.js
deleted file mode 100644
index ed0e990c..00000000
--- a/vnext/src/ui/Login.js
+++ /dev/null
@@ -1,88 +0,0 @@
-import { useEffect } from 'react'
-import { useLocation, useNavigate } from 'react-router-dom'
-
-import Icon from './Icon'
-import Button from './Button'
-import { useForm } from 'react-hook-form'
-
-import { me, facebookLink, vkLink, appleLink } from '../api'
-
-import { useVisitor } from './VisitorContext'
-
-/**
- * @typedef {object} LoginProps
- * @property {Function} onAuth
- */
-
-/**
- * Login page
- * @param {LoginProps} props
- */
-function Login({ onAuth }) {
- const location = useLocation()
- const navigate = useNavigate()
- const [visitor] = useVisitor()
- useEffect(() => {
- if (visitor && visitor.hash) {
- const retpath = location.state?.retpath || '/'
- console.log(retpath)
- navigate(retpath)
- }
- }, [navigate, location.state, visitor])
-
- const { register, handleSubmit } = useForm()
-
- /** @type { import('react-hook-form').SubmitHandler<import('react-hook-form').FieldValues> } */
- let onSubmit = (values) => {
- me(values.username, values.password)
- .then(response => {
- onAuth(response)
- }
- ).catch(ex => {
- console.log(ex)
- })
- }
- return (
- <div className="msg-cont">
- <div className="dialoglogin">
- <p>Please, introduce yourself:</p>
- <div style={socialButtonsStyle}>
- <a href={facebookLink()} style={facebookButtonStyle}>
- <Icon name="ei-sc-facebook" size="s" noFill={true} />Log in
- </a>
- <a href={vkLink()} style={vkButtonStyle}>
- <Icon name="ei-sc-vk" size="s" noFill={true} />
- Log in
- </a>
- <a href={appleLink()}><img src="https://appleid.cdn-apple.com/appleid/button" /></a>
- </div>
- <p>Already registered?</p>
- <form onSubmit={handleSubmit(onSubmit)}>
- <input placeholder="Username..." {...register('username')} /><br />
- <input placeholder="Password..." type="password" {...register('password')} /><br />
- <Button onClick={handleSubmit(onSubmit)}>OK</Button>
- </form>
- </div>
- </div>
- )
-}
-
-export default Login
-
-const socialButtonsStyle = {
- display: 'flex',
- justifyContent: 'space-evenly',
- padding: '4px'
-}
-
-const facebookButtonStyle = {
- color: '#fff',
- padding: '2px 14px',
- background: '#3b5998'
-}
-
-const vkButtonStyle = {
- color: '#fff',
- padding: '2px 14px',
- background: '#4c75a3'
-}
diff --git a/vnext/src/ui/Message.js b/vnext/src/ui/Message.js
index eba0f327..eaac8eba 100644
--- a/vnext/src/ui/Message.js
+++ b/vnext/src/ui/Message.js
@@ -112,10 +112,10 @@ export default function Message({ data, isThread, onToggleSubscription, children
<span>{likesSummary}</span>
</Link>
) : (
- <Link to="/login" className="a-login msg-button">
+ <a href={`/login?retpath=${window.location.href}`} className="a-login msg-button">
<Icon name="ei-heart" size="s" />
<span>{likesSummary}</span>
- </Link>
+ </a>
)}
{
data.user && canComment && ((