onedrive/components/Auth.tsx

61 lines
2.1 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'
2022-01-06 11:25:10 +00:00
import { FC, useState } from 'react'
2021-08-30 00:35:52 +00:00
import { matchProtectedRoute } from '../utils/protectedRouteHandler'
2021-08-30 00:35:52 +00:00
import useLocalStorage from '../utils/useLocalStorage'
2022-01-06 11:25:10 +00:00
const Auth: FC<{ redirect: string }> = ({ redirect }) => {
2021-08-30 00:35:52 +00:00
const authTokenPath = matchProtectedRoute(redirect)
const router = useRouter()
const [token, setToken] = useState('')
2022-01-02 15:32:16 +00:00
const [_, setPersistedToken] = useLocalStorage(authTokenPath, '')
2021-08-30 00:35:52 +00:00
return (
2021-09-04 14:15:09 +00:00
<div className="md:my-10 flex flex-col max-w-sm mx-auto space-y-4">
<div className="md:w-5/6 w-3/4 mx-auto">
2022-01-02 15:32:16 +00:00
<Image src={'/images/fabulous-wapmire-weekdays.png'} alt="authenticate" width={912} height={912} priority />
2021-08-30 13:34:37 +00:00
</div>
2021-09-04 14:15:09 +00:00
<div className="dark:text-gray-100 text-lg font-bold text-gray-900">Enter Password</div>
2021-08-30 13:34:37 +00:00
<p className="text-sm text-gray-500 font-medium">
2021-08-30 13:34:37 +00:00
This route (the folder itself and the files inside) is password protected. If you know the password, please
enter it below.
</p>
<div className="flex items-center space-x-2">
<input
className="flex-1 border border-gray-600/10 dark:bg-gray-600 dark:text-white focus:ring focus:ring-blue-300 dark:focus:ring-blue-700 focus:outline-none p-2 font-mono rounded"
autoFocus
type="text"
placeholder="************"
value={token}
onChange={e => {
setToken(e.target.value)
}}
onKeyPress={e => {
if (e.key === 'Enter' || e.key === 'NumpadEnter') {
setPersistedToken(token)
router.reload()
}
}}
/>
<button
className="focus:outline-none focus:ring focus:ring-blue-400 hover:bg-blue-500 px-4 py-2 text-white bg-blue-600 rounded"
onClick={() => {
2021-12-20 14:33:49 +00:00
setPersistedToken(token)
2021-08-30 13:44:50 +00:00
router.reload()
}}
>
<FontAwesomeIcon icon="arrow-right" />
</button>
</div>
2021-08-30 00:35:52 +00:00
</div>
)
}
export default Auth