mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-12 04:42:16 +00:00
catch failed login
This commit is contained in:
1 parent
2c35840a8d
commit
d6947f7712
2 files changed
+14
-3
No files matched your search
@@ -20,7 +20,11 @@ export const AuthenticationContext = createContext<{
|
||||
authState?: AuthState,
|
||||
setAuthState?: Dispatch<SetStateAction<AuthState | undefined>>,
|
||||
persistLoginOrOut?: ()=>void,
|
||||
loginAndGetUserInfo?: (usernameOrEmail: string, password:string)=>void;
|
||||
loginAndGetUserInfo?: (
|
||||
usernameOrEmail: string,
|
||||
password:string,
|
||||
failureCallback?:()=>void
|
||||
)=>void;
|
||||
logout?: ()=>void;
|
||||
}>({});
|
||||
|
||||
@@ -44,7 +48,7 @@ export const AuthenticationProvider = ({children}:{children:ReactNode})=>{
|
||||
});
|
||||
}, []);
|
||||
|
||||
const loginAndGetUserInfo = (usernameOrEmail: string, password:string)=>{
|
||||
const loginAndGetUserInfo = (usernameOrEmail: string, password:string, failureCallback?:()=>void)=>{
|
||||
CreateSession({usernameOrEmail, password})
|
||||
.then((respond)=>{
|
||||
GetSession().then((
|
||||
@@ -56,6 +60,8 @@ export const AuthenticationProvider = ({children}:{children:ReactNode})=>{
|
||||
isLoggedIn: true,
|
||||
userInfo: res.user
|
||||
});
|
||||
}else{
|
||||
if(failureCallback) failureCallback();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,7 +32,12 @@ export default function LoginScreen() {
|
||||
const password = form.get("password")?.toString();
|
||||
if( usernameOrEmail && password && loginAndGetUserInfo){
|
||||
setShowLoader("Authenticating");
|
||||
loginAndGetUserInfo(usernameOrEmail, password);
|
||||
loginAndGetUserInfo(
|
||||
usernameOrEmail,
|
||||
password,
|
||||
()=>{
|
||||
setShowLoader(undefined);
|
||||
});
|
||||
}
|
||||
}
|
||||
}// end handleOnSubmit
|
||||
|
||||
Reference in new issue
Block a user