Added reservation and username lookup
All checks were successful
Build BAB Application Deployment Artifact / build (push) Successful in 2m13s
All checks were successful
Build BAB Application Deployment Artifact / build (push) Successful in 2m13s
This commit is contained in:
@@ -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,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user