diff --git a/README.md b/README.md index b3df086..f1ab924 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,10 @@ See the [Features](#features) for more functionalities - [x] the url same as hosting - [x] dynamic sitemap - [x] firebase-storage - - [x] profile picture + - [x] profile photo + - [x] cover photo + - [x] firestore + - [x] user collection - [x] firebase-auth - [x] firebase-auth password - [x] register diff --git a/functions/src/api/authApi.ts b/functions/src/api/authApi.ts index 7bee750..afbb7b8 100644 --- a/functions/src/api/authApi.ts +++ b/functions/src/api/authApi.ts @@ -1,6 +1,6 @@ import express, { Request, Response, Router } from 'express'; import { addDecodedIdToken } from '../service/firebase-admin-utils'; -import { DefaultUserPhoto, StoredUser } from '../types' +import { User, UserDTO } from '../types' import admin from '../service/firebase-admin-init'; import { FirebaseError } from "firebase-admin"; import { RuntimeOptions, runWith } from "firebase-functions"; @@ -30,26 +30,24 @@ router.post(service, async (req: Request, res: Response) => { } return await addDecodedIdToken(req.body.token) - .then((decodedIdToken: admin.auth.DecodedIdToken) => { - const alt = decodedIdToken.name as string || decodedIdToken.email as string; + .then(async (decodedIdToken: admin.auth.DecodedIdToken) => { + const user = await admin.firestore().doc(decodedIdToken.sub).get().then((document) => { + return document.data() as User + }) + if (!user) { + throw new Error('User not found by id: ' + decodedIdToken.sub) + } - const profilePhoto = decodedIdToken.picture ? - { - src: decodedIdToken.picture, - alt: 'Picture of ' + alt - } - : DefaultUserPhoto - - const user: StoredUser = { + const storedUser: UserDTO = { name: decodedIdToken.name, verified: decodedIdToken.email_verified as boolean, email: decodedIdToken.email as string, - profilePhoto, + profilePhoto: user.profilePhoto, userId: decodedIdToken.sub, providers: [{ providerType: decodedIdToken.firebase.sign_in_provider }] }; - return res.status(200).json(user); + return res.status(200).json(storedUser); }) .catch((error) => handleFirebaseError(res, error, '/api' + service)); }); diff --git a/functions/src/types.ts b/functions/src/types.ts index 9ddfa0e..e3fa419 100644 --- a/functions/src/types.ts +++ b/functions/src/types.ts @@ -1,3 +1,5 @@ +import { BaseCollection } from "../../src/types"; + export interface Image { src: string; alt: string; @@ -5,16 +7,11 @@ export interface Image { default?: boolean } -export const DefaultUserPhoto: Image = { - src: '/img/default-profile.svg', - alt: ' user default picture' -} - export interface ProviderData { providerType: string } -export interface StoredUser { +export interface UserDTO { name: string email: string profilePhoto: Image @@ -22,3 +19,11 @@ export interface StoredUser { verified: boolean providers: ProviderData[] } + +export interface User extends BaseCollection { + id: string + name: string + surname: string + profilePhoto: Image + coverPhoto: Image +} diff --git a/src/components/image/upload/SingleFileUpload.vue b/src/components/image/upload/SingleFileUpload.vue index 412a1ef..6635107 100644 --- a/src/components/image/upload/SingleFileUpload.vue +++ b/src/components/image/upload/SingleFileUpload.vue @@ -53,8 +53,8 @@ name: this.fileName, src: downloadURL, alt: this.getAltValue(this.file?.name || ''), + default: false } - this.uploadCompleted(image) }); }); diff --git a/src/components/navbar/ProfileNavigator.vue b/src/components/navbar/ProfileNavigator.vue index 75c32db..f486c20 100644 --- a/src/components/navbar/ProfileNavigator.vue +++ b/src/components/navbar/ProfileNavigator.vue @@ -10,7 +10,7 @@ - + {{$t('topNavbar.profile')}} @@ -26,20 +26,20 @@ diff --git a/src/components/profile/Profile.vue b/src/components/profile/Profile.vue index 25c14af..97ad530 100644 --- a/src/components/profile/Profile.vue +++ b/src/components/profile/Profile.vue @@ -1,7 +1,7 @@