-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: added login api with login form
- Loading branch information
1 parent
57f2fe1
commit 330796e
Showing
5 changed files
with
68 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export interface LoginForm { | ||
email: string | ||
password: string | ||
} | ||
|
||
export interface UserResponseType { | ||
user: User | ||
tokens: Tokens | ||
} | ||
|
||
export interface User { | ||
firstName: string | ||
lastName: string | ||
email: string | ||
gender: string | ||
dob: string | ||
role: string | ||
isEmailVerified: boolean | ||
id: string | ||
} | ||
|
||
export interface Tokens { | ||
access: Access | ||
refresh: Refresh | ||
} | ||
|
||
export interface Access { | ||
token: string | ||
expires: string | ||
} | ||
|
||
export interface Refresh { | ||
token: string | ||
expires: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { AxiosError } from 'axios' | ||
|
||
export type StatusType = 'idle' | 'pending' | 'resolved' | 'rejected' | ||
export type ErrorType = Error | AxiosError | string | symbol | null | ||
|
||
export type PromiseResolve = (<T>(val: T) => void) | undefined | ||
export type PromiseReject = (<T>(err: T) => void) | undefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { LoginForm, UserResponseType } from '@/models/auth' | ||
import { useMutation } from '@tanstack/react-query' | ||
import { client } from './api-Client' | ||
|
||
const login = async (data: LoginForm): Promise<UserResponseType> => { | ||
const result = await client<UserResponseType, LoginForm>('auth/login', { data }) | ||
return result | ||
} | ||
|
||
export const useHandleLogin = () => | ||
useMutation({ | ||
mutationFn: (data: LoginForm) => login(data), | ||
onSuccess: (response) => { | ||
console.log(response, 'response') | ||
}, | ||
}) |