mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
added usernameValidation
This commit is contained in:
parent
49cf17b33c
commit
a06e559b58
@ -1,6 +1,8 @@
|
||||
import request from "../../handlers/request"
|
||||
import SessionModel from "../session"
|
||||
|
||||
const emailRegex = new RegExp(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/)
|
||||
|
||||
export default class AuthModel {
|
||||
static login = async (payload) => {
|
||||
const response = await request({
|
||||
@ -50,4 +52,31 @@ export default class AuthModel {
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
static usernameValidation = async (username) => {
|
||||
let payload = {}
|
||||
|
||||
// check if usename arguemnt is an email
|
||||
if (emailRegex.test(username)) {
|
||||
payload.email = username
|
||||
} else {
|
||||
payload.username = username
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: "get",
|
||||
url: "/auth/login/validation",
|
||||
params: payload,
|
||||
}).catch((error) => {
|
||||
console.error(error)
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
if (!response) {
|
||||
throw new Error("Unable to validate user")
|
||||
}
|
||||
|
||||
return response.data
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user