feat: add rate limit for authentication

* improve error handling in frontend
This commit is contained in:
wancat committed 2023-11-01 22:11:17 +08:00
1 parent 203114cd5e
commit f65b72c5b4
10 files changed
+146 -42

No files matched your search

+17 -1
View File
@@ -2,14 +2,30 @@
import AuthForm from '../components/AuthForm.vue'
import Background from '../components/DynamicBackground.vue'
import {
TooManyRequestsError,
UnauthorizedError,
ValidationError,
} from '../utils/errors'
import { login } from '../utils/auth'
const handleLogin = async ({ username, password, success, error }) => {
try {
const isSuccess = await login(username, password)
if (isSuccess) success()
else error('Wrong username or password.')
} catch (err) {
if (err instanceof TooManyRequestsError) {
error('Too many requests. Try again in 2 minutes.')
return
}
if (err instanceof UnauthorizedError) {
error('Wrong username or password.')
return
}
if (err instanceof ValidationError) {
error('Invalid username or password.')
return
}
console.error(err)
error('Something went wrong.')
}