Rename userLoadingFinished to loadingUserFinished

This commit is contained in:
Maciej Pędzich 2023-05-26 12:22:09 +02:00
parent d0207363bf
commit ad0558d7cb

View File

@ -4,7 +4,7 @@ import { Models } from 'appwrite';
import { account } from '@/appwrite'; import { account } from '@/appwrite';
const user = ref<Models.User<Models.Preferences> | null>(null); const user = ref<Models.User<Models.Preferences> | null>(null);
const userLoadingFinished = ref(false); const loadingUserFinished = ref(false);
const isLoggedIn = computed(() => !!user.value); const isLoggedIn = computed(() => !!user.value);
export function useAuth() { export function useAuth() {
@ -17,24 +17,20 @@ export function useAuth() {
account.createOAuth2Session( account.createOAuth2Session(
provider, provider,
`${location.origin}${redirectPath}`, `${location.origin}${redirectPath}#login-success`,
`${location.origin}/log-in#oauth-error`, `${location.origin}/log-in#login-error`,
permissionScopes permissionScopes
); );
}; };
const loadUser = async () => { const loadUser = async () => {
try { try {
if (userLoadingFinished.value) return; if (loadingUserFinished.value) return;
const currentUser = await account.get(); const currentUser = await account.get();
user.value = currentUser; user.value = currentUser;
} catch (error) {
// TODO: Add to globaL Vue error logger and implement snackbar message bus
console.error(error);
user.value = null;
} finally { } finally {
userLoadingFinished.value = true; loadingUserFinished.value = true;
} }
}; };
@ -45,7 +41,7 @@ export function useAuth() {
return { return {
user, user,
userLoadingFinished, loadingUserFinished,
isLoggedIn, isLoggedIn,
logIn, logIn,
loadUser, loadUser,