refactor: improvements to the auth implementation in admin dashboard (#3444)
* refactor: abstract axios queries to a separate helper file * chore: delete unnecessary file * chore: remove unnecessary console logs * refactor: updated urls for api and authquery helpers * refactor: updated auth implementation * refactor: use default axios instance * chore: improve code readability * refactor: separate instances for rest and gql calls * refactor: removed async await from functions that do not need them * refactor: removed probable login and probable user from the auth system * refactor: better error handling in login component * chore: deleted unnecessary files and restructured some files * feat: new errors file with typed error message formats * refactor: removed unwanted usage of async await * refactor: optimizing the usage and return of promises in auth flow * refactor: convey boolean return type in a better way * chore: apply suggestions * refactor: handle case when mailcatcher is not active --------- Co-authored-by: nivedin <nivedinp@gmail.com> Co-authored-by: James George <jamesgeorge998001@gmail.com>
This commit is contained in:
committed by
GitHub
parent
46caf9b198
commit
7a9f0c8756
@@ -89,8 +89,8 @@ const t = useI18n();
|
||||
const { isOpen, isExpanded } = useSidebar();
|
||||
|
||||
const currentUser = useReadonlyStream(
|
||||
auth.getProbableUserStream(),
|
||||
auth.getProbableUser()
|
||||
auth.getCurrentUserStream(),
|
||||
auth.getCurrentUser()
|
||||
);
|
||||
|
||||
const expandSidebar = () => {
|
||||
|
||||
@@ -184,91 +184,71 @@ onMounted(() => {
|
||||
subscribeToStream(currentUser$, (user) => {
|
||||
if (user && !user.isAdmin) {
|
||||
nonAdminUser.value = true;
|
||||
toast.error(`${t('state.non_admin_login')}`);
|
||||
toast.error(t('state.non_admin_login'));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
async function signInWithGoogle() {
|
||||
const signInWithGoogle = () => {
|
||||
signingInWithGoogle.value = true;
|
||||
|
||||
try {
|
||||
await auth.signInUserWithGoogle();
|
||||
auth.signInUserWithGoogle();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
/*
|
||||
A auth/account-exists-with-different-credential Firebase error wont happen between Google and any other providers
|
||||
Seems Google account overwrites accounts of other providers https://github.com/firebase/firebase-android-sdk/issues/25
|
||||
*/
|
||||
toast.error(`${t('state.google_signin_failure')}`);
|
||||
toast.error(t('state.google_signin_failure'));
|
||||
}
|
||||
|
||||
signingInWithGoogle.value = false;
|
||||
}
|
||||
async function signInWithGithub() {
|
||||
};
|
||||
|
||||
const signInWithGithub = () => {
|
||||
signingInWithGitHub.value = true;
|
||||
|
||||
try {
|
||||
await auth.signInUserWithGithub();
|
||||
auth.signInUserWithGithub();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
/*
|
||||
A auth/account-exists-with-different-credential Firebase error wont happen between Google and any other providers
|
||||
Seems Google account overwrites accounts of other providers https://github.com/firebase/firebase-android-sdk/issues/25
|
||||
*/
|
||||
toast.error(`${t('state.github_signin_failure')}`);
|
||||
toast.error(t('state.github_signin_failure'));
|
||||
}
|
||||
|
||||
signingInWithGitHub.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
async function signInWithMicrosoft() {
|
||||
const signInWithMicrosoft = () => {
|
||||
signingInWithMicrosoft.value = true;
|
||||
|
||||
try {
|
||||
await auth.signInUserWithMicrosoft();
|
||||
auth.signInUserWithMicrosoft();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
/*
|
||||
A auth/account-exists-with-different-credential Firebase error wont happen between MS with Google or Github
|
||||
If a Github account exists and user then logs in with MS email we get a "Something went wrong toast" and console errors and MS replaces GH as only provider.
|
||||
The error messages are as follows:
|
||||
FirebaseError: Firebase: Error (auth/popup-closed-by-user).
|
||||
@firebase/auth: Auth (9.6.11): INTERNAL ASSERTION FAILED: Pending promise was never set
|
||||
They may be related to https://github.com/firebase/firebaseui-web/issues/947
|
||||
*/
|
||||
toast.error(`${t('state.error')}`);
|
||||
toast.error(t('state.microsoft_signin_failure'));
|
||||
}
|
||||
|
||||
signingInWithMicrosoft.value = false;
|
||||
}
|
||||
async function signInWithEmail() {
|
||||
signingInWithEmail.value = true;
|
||||
};
|
||||
|
||||
await auth
|
||||
.signInWithEmail(form.value.email)
|
||||
.then(() => {
|
||||
mode.value = 'email-sent';
|
||||
setLocalConfig('emailForSignIn', form.value.email);
|
||||
})
|
||||
.catch((e: any) => {
|
||||
console.error(e);
|
||||
toast.error(e.message);
|
||||
signingInWithEmail.value = false;
|
||||
})
|
||||
.finally(() => {
|
||||
signingInWithEmail.value = false;
|
||||
});
|
||||
}
|
||||
const signInWithEmail = async () => {
|
||||
signingInWithEmail.value = true;
|
||||
try {
|
||||
await auth.signInWithEmail(form.value.email);
|
||||
mode.value = 'email-sent';
|
||||
setLocalConfig('emailForSignIn', form.value.email);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
toast.error(t('state.email_signin_failure'));
|
||||
}
|
||||
signingInWithEmail.value = false;
|
||||
};
|
||||
|
||||
const logout = async () => {
|
||||
try {
|
||||
await auth.signOutUser();
|
||||
window.location.reload();
|
||||
toast.success(`${t('state.logged_out')}`);
|
||||
toast.success(t('state.logged_out'));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
toast.error(`${t('state.error')}`);
|
||||
toast.error(t('state.error'));
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -200,7 +200,7 @@ import {
|
||||
} from '../../helpers/backend/graphql';
|
||||
import { useToast } from '~/composables/toast';
|
||||
import { useMutation, useQuery } from '@urql/vue';
|
||||
import { Email, EmailCodec } from '~/helpers/backend/Email';
|
||||
import { Email, EmailCodec } from '~/helpers/Email';
|
||||
import IconTrash from '~icons/lucide/trash';
|
||||
import IconPlus from '~icons/lucide/plus';
|
||||
import IconCircleDot from '~icons/lucide/circle-dot';
|
||||
|
||||
Reference in New Issue
Block a user