Added reservation and username lookup
All checks were successful
Build BAB Application Deployment Artifact / build (push) Successful in 2m13s

This commit is contained in:
2024-05-13 10:49:03 -04:00
parent 4a273ccb2f
commit 78211a33ae
17 changed files with 180 additions and 72 deletions

View File

@@ -1,10 +1,11 @@
import { defineStore } from 'pinia';
import { ID, account } from 'boot/appwrite';
import { OAuthProvider, type Models } from 'appwrite';
import { ID, account, functions } from 'boot/appwrite';
import { ExecutionMethod, OAuthProvider, type Models } from 'appwrite';
import { ref } from 'vue';
export const useAuthStore = defineStore('auth', () => {
const currentUser = ref<Models.User<Models.Preferences> | null>(null);
const userNames = ref<Record<string, string>>({});
async function init() {
try {
@@ -31,9 +32,39 @@ export const useAuthStore = defineStore('auth', () => {
currentUser.value = await account.get();
}
function getUserNameById(id: string) {
try {
if (!userNames.value[id]) {
userNames.value[id] = '';
functions
.createExecution(
'664038294b5473ef0c8d',
'',
false,
'/userinfo/' + id,
ExecutionMethod.GET
)
.then(
(res) => (userNames.value[id] = JSON.parse(res.responseBody).name)
);
}
} catch (e) {
console.log('Failed to get username. Error: ' + e);
}
return userNames.value[id];
}
function logout() {
return account.deleteSession('current').then((currentUser.value = null));
}
return { currentUser, register, login, googleLogin, logout, init };
return {
currentUser,
getUserNameById,
register,
login,
googleLogin,
logout,
init,
};
});