diff --git a/layouts/board.vue b/layouts/board.vue
index ad6080a..01da9e3 100644
--- a/layouts/board.vue
+++ b/layouts/board.vue
@@ -10,13 +10,18 @@
- {{ state.displayName }}
+ {{ authState.user.displayName }}
-
+
@@ -159,28 +164,19 @@ import {
useContext,
} from 'nuxt-composition-api';
import { useState } from '../plugins/state';
-import { useFirebaseAuth, useFirestore } from '../plugins/firebase';
+import { useFirebaseAuth } from '../plugins/firebase';
export default defineComponent({
setup() {
const state = reactive({
display: false,
- displayName: '',
});
const context = useContext();
const authState = useState();
- useFetch(async () => {
+ useFetch(() => {
if (!authState.user.loggedIn) context.redirect('/');
-
- const db = useFirestore();
- const userData = await db
- .collection('users')
- .doc(authState.user.uid)
- .get();
-
- state.displayName = userData.data()?.displayName;
});
async function logOut() {
@@ -192,6 +188,7 @@ export default defineComponent({
uid: '',
email: '',
loggedIn: false,
+ admin: false,
};
context.redirect('/');
diff --git a/pages/index.vue b/pages/index.vue
index b9de85b..9a4a3a3 100644
--- a/pages/index.vue
+++ b/pages/index.vue
@@ -32,7 +32,7 @@ import {
useFetch,
useContext,
} from 'nuxt-composition-api';
-import { useFirebaseAuth } from '../plugins/firebase';
+import { useFirebaseAuth, useFirestore } from '../plugins/firebase';
import { useState } from '../plugins/state';
import { StateType } from '../plugins/types';
@@ -49,6 +49,7 @@ export default defineComponent({
const passwordProv = ref('');
const auth = useFirebaseAuth();
+ const firestore = useFirestore();
async function signInWithEmailAndPassword() {
try {
@@ -57,10 +58,20 @@ export default defineComponent({
passwordProv.value,
);
- if (user && user.user) {
+ const dataResult = await firestore
+ .collection('users')
+ .doc(user.user?.uid)
+ .get();
+
+ const userData = dataResult.data();
+
+ if (user.user && userData) {
authState.user = {
uid: user.user.uid,
email: user.user.email,
+ displayName: userData.displayName,
+ profilePicture: userData.profilePicture,
+ admin: userData.admin,
loggedIn: true,
};
diff --git a/pages/plugin/_prefix/admin.vue b/pages/plugin/_prefix/admin.vue
index f4d2a58..1176c8f 100644
--- a/pages/plugin/_prefix/admin.vue
+++ b/pages/plugin/_prefix/admin.vue
@@ -7,9 +7,16 @@