💄 Display loading spinners while authenticating

This commit is contained in:
Philipp Stracker 2025-02-12 15:24:35 +01:00
parent 1f3a18a690
commit 2c4df18728
No known key found for this signature in database

View file

@ -173,6 +173,7 @@ const useConnectionBase = () => {
const { createSuccessNotice, createErrorNotice } =
useDispatch( noticesStore );
const { verifyLoginStatus } = CommonHooks.useMerchantInfo();
const { withActivity } = CommonHooks.useBusyState();
return {
handleFailed: ( res, genericMessage ) => {
@ -180,18 +181,26 @@ const useConnectionBase = () => {
createErrorNotice( res?.message ?? genericMessage );
},
handleCompleted: async () => {
try {
const loginSuccessful = await verifyLoginStatus();
await withActivity(
'auth',
'Verifying Authentication',
async () => {
try {
const loginSuccessful = await verifyLoginStatus();
if ( loginSuccessful ) {
createSuccessNotice( MESSAGES.CONNECTED );
await setCompleted( true );
} else {
createErrorNotice( MESSAGES.LOGIN_FAILED );
if ( loginSuccessful ) {
createSuccessNotice( MESSAGES.CONNECTED );
await setCompleted( true );
} else {
createErrorNotice( MESSAGES.LOGIN_FAILED );
}
} catch ( error ) {
createErrorNotice(
error.message ?? MESSAGES.LOGIN_FAILED
);
}
}
} catch ( error ) {
createErrorNotice( error.message ?? MESSAGES.LOGIN_FAILED );
}
);
},
createErrorNotice,
};