33 lines
653 B
TypeScript
33 lines
653 B
TypeScript
import { create } from 'zustand'
|
|
import axios from 'axios'
|
|
|
|
type AuthState = {
|
|
credential?: {
|
|
username: string,
|
|
password: string
|
|
};
|
|
verify: (username: string, password: string) => Promise<boolean>
|
|
}
|
|
|
|
export default create<AuthState>(set => ({
|
|
verify: async (username: string, password: string): Promise<boolean> => {
|
|
try {
|
|
const res = await axios.get("https://api.feedbin.com/v2/authentication.json", {
|
|
auth: { username, password }
|
|
})
|
|
|
|
console.log("verifying")
|
|
|
|
if (res.status > 299) return false
|
|
|
|
set({
|
|
credential: { username, password }
|
|
})
|
|
return true
|
|
} catch(e) {
|
|
console.log(e)
|
|
return false
|
|
}
|
|
}
|
|
}))
|