onedrive/components/Auth.tsx

57 lines
1.9 KiB
TypeScript
Raw Normal View History

2021-08-30 00:35:52 +00:00
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import Image from 'next/image'
import { useRouter } from 'next/router'
2021-08-30 13:34:37 +00:00
import { FunctionComponent } from 'react'
2021-08-30 00:35:52 +00:00
import { matchProtectedRoute } from '../utils/tools'
import useLocalStorage from '../utils/useLocalStorage'
const Auth: FunctionComponent<{ redirect: string }> = ({ redirect }) => {
const authTokenPath = matchProtectedRoute(redirect)
const router = useRouter()
const [token, setToken] = useLocalStorage(authTokenPath, '')
return (
2021-08-30 13:34:37 +00:00
<div className="flex flex-col space-y-4 max-w-sm mx-auto md:my-10">
<div className="mx-auto w-3/4 md:w-5/6">
<Image src={'/images/no-looking.png'} alt="authenticate" width={912} height={912} />
</div>
<div className="dark:text-gray-100 text-gray-900 text-lg font-bold">Enter Password</div>
<p className="text-sm text-gray-500">
This route (the folder itself and the files inside) is password protected. If you know the password, please
enter it below.
</p>
2021-08-30 00:35:52 +00:00
<input
2021-08-30 13:34:37 +00:00
className="font-mono p-2 bg-blue-50 dark:bg-gray-600 dark:text-white rounded focus:ring focus:ring-blue-300 dark:focus:ring-blue-700 focus:outline-none"
2021-08-30 14:51:19 +00:00
autoFocus
2021-08-30 00:35:52 +00:00
type="text"
2021-08-30 13:34:37 +00:00
placeholder="************"
2021-08-30 00:35:52 +00:00
value={token}
onChange={e => {
setToken(e.target.value)
}}
2021-08-30 13:44:50 +00:00
onKeyPress={e => {
if (e.key === 'Enter' || e.key === 'NumpadEnter') {
router.reload()
}
}}
2021-08-30 00:35:52 +00:00
/>
<button
2021-08-30 13:34:37 +00:00
className="inline-flex space-x-2 items-center justify-center bg-blue-500 rounded py-2 px-4 text-white focus:outline-none focus:ring focus:ring-blue-300 hover:bg-blue-600"
2021-08-30 00:35:52 +00:00
onClick={() => {
router.reload()
}}
>
2021-08-30 13:34:37 +00:00
<span>Lemme in</span>
2021-08-30 00:35:52 +00:00
<FontAwesomeIcon icon="arrow-right" />
</button>
</div>
)
}
export default Auth