Skip to content

Commit ded017e

Browse files
firebase project changed, readme updated
1 parent 8f97572 commit ded017e

File tree

10 files changed

+61
-129
lines changed

10 files changed

+61
-129
lines changed

.firebaserc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"projects": {
3-
"default": "ionic-angular-project-a9d42"
3+
"default": "ionic-angular-pr-1565107344855"
44
}
55
}

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Code taken from course.
1919
* App to view and book places to stay. All places listed on the 'discover.page' and clicking on an item navigates to a place detail page using the place id in the browser.
2020
* Places are displayed under 2 list option: 'ALL PLACES' and 'BOOKABLE PLACES'. The first place is displayed using an ion-card, the remaining places are displayed using a list with a thumbnail image. There is code to prevent the user from being able to book their own places, using a userId matching function.
2121
* Places can be booked, listed and cancelled.
22-
* New places can be added. The location of the new place is chosen using google maps and is stored in the Places array to be displayed in the template using data-binding. A photo can be taken to add to the new Place description. If there is no camera then there is a file upload button to save a jpeg image.
22+
* New places can be added. The location of the new place is chosen using google maps and is displayed in the template using data-binding. A photo can be taken to add to the new Place description. If there is no camera then there is a file upload button to save a jpeg image.
2323
* Burger side panel added with links to the discover places listings, your bookings and a logout button.
2424
* Bottom menu with 2 links to 'Discover' (default page upon loading) and 'Offers' that lists all the places available.
2525

@@ -104,11 +104,12 @@ private getGoogleMaps(): Promise<any> {
104104
* [Capacitor Camera API](https://capacitor.ionicframework.com/docs/apis/camera) used to provide camera functionality.
105105
* [Firebase Auth API](https://firebase.google.com/docs/reference/rest/auth) used to control access to app.
106106
* [Cordova Local Storage](https://cordova.apache.org/docs/en/latest/cordova/storage/storage.html#localstorage) to save user user authentication token so a refresh etc. does not lose a user's settings.
107+
* [Google Cloud Storage](https://www.npmjs.com/package/@google-cloud/storage) used for storage of image data.
107108
* Auth tokens on the backend.
108109

109110
## Status & To-do list
110111

111-
* Status: Working but missing functionality.
112+
* Status: issue with auth token means user is logged out immediately. New database used which is currently empty.
112113
* To-do: complete course
113114

114115
## Inspiration

functions/index.js

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,14 @@ const uuid = require('uuid/v4');
99
const { Storage } = require('@google-cloud/storage');
1010

1111
const storage = new Storage({
12-
projectId: 'ionic-angular-project-a9d42'
12+
projectId: 'ionic-angular-pr-1565107344855'
1313
});
1414

1515
exports.storeImage = functions.https.onRequest((req, res) => {
1616
return cors(req, res, () => {
1717
if (req.method !== 'POST') {
1818
return res.status(500).json({ message: 'Not allowed.' });
1919
}
20-
21-
if (!req.headers.authorizaton || !req.headers.authorizaton.startsWith('Bear ')) {
22-
return res.status(401).json({ error: 'Unauthorized' });
23-
}
24-
25-
let idToken;
26-
idToken = req.headers.authorization.split('Bearer ')[1];
27-
2820
const busboy = new Busboy({ headers: req.headers });
2921
let uploadData;
3022
let oldImagePath;
@@ -46,29 +38,25 @@ exports.storeImage = functions.https.onRequest((req, res) => {
4638
imagePath = oldImagePath;
4739
}
4840

49-
return fbAdmin
50-
.auth()
51-
.verifyIdToken(idToken)
52-
.then(decodedToken => {
53-
console.log(uploadData.type);
54-
return storage
55-
.bucket('ionic-angular-project-a9d42.appspot.com')
56-
.upload(uploadData.filePath, {
57-
uploadType: 'media',
58-
destination: imagePath,
59-
metadata: {
60-
metadata: {
61-
contentType: uploadData.type,
62-
firebaseStorageDownloadTokens: id
63-
}
64-
}
65-
})
41+
console.log(uploadData.type);
42+
return storage
43+
.bucket('ionic-angular-pr-1565107344855.appspot.com')
44+
.upload(uploadData.filePath, {
45+
uploadType: 'media',
46+
destination: imagePath,
47+
metadata: {
48+
metadata: {
49+
contentType: uploadData.type,
50+
firebaseStorageDownloadTokens: id
51+
}
52+
}
6653
})
54+
6755
.then(() => {
6856
return res.status(201).json({
6957
imageUrl:
7058
'https://firebasestorage.googleapis.com/v0/b/' +
71-
storage.bucket('ionic-angular-project-a9d42.appspot.com').name +
59+
storage.bucket('ionic-angular-pr-1565107344855.appspot.com').name +
7260
'/o/' +
7361
encodeURIComponent(imagePath) +
7462
'?alt=media&token=' +

functions/package-lock.json

Lines changed: 23 additions & 82 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

functions/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
"node": "8"
1313
},
1414
"dependencies": {
15-
"@google-cloud/storage": "^3.0.4",
16-
"busboy": "^0.3.1",
17-
"cors": "^2.8.5",
1815
"firebase-admin": "^8.0.0",
1916
"firebase-functions": "^3.1.0",
20-
"uuid": "^3.3.2"
17+
"@google-cloud/storage": "3.1.0",
18+
"busboy": "0.3.1",
19+
"cors": "2.8.5",
20+
"uuid": "3.3.2"
2121
},
2222
"devDependencies": {
2323
"firebase-functions-test": "^0.1.6"

src/app/auth/auth.page.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class AuthPage implements OnInit {
4040
}
4141
authObs.subscribe(
4242
resData => {
43+
console.log(resData);
4344
this.isLoading = false;
4445
loadingEl.dismiss();
4546
this.router.navigateByUrl('/places/tabs/discover');

src/app/auth/auth.service.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import { environment } from '../../environments/environment';
88
import { User } from './user.model';
99

1010
export interface AuthResponseData {
11+
kind: string;
1112
idToken: string;
1213
email: string;
1314
refreshToken: string;
14-
expiresIn: string;
1515
localId: string;
16+
expiresIn: string;
1617
registered?: boolean;
1718
}
1819

@@ -157,8 +158,7 @@ export class AuthService implements OnDestroy {
157158
userData.email,
158159
userData.idToken,
159160
expirationTime
160-
)
161-
;
161+
);
162162
this._user.next(user);
163163
this.autoLogout(user.tokenDuration);
164164
this.storeAuthData(
@@ -181,6 +181,7 @@ export class AuthService implements OnDestroy {
181181
tokenExpirationDate,
182182
email
183183
});
184+
console.log('auth data: ', data);
184185
Plugins.Storage.set({ key: 'authData', value: data });
185186
}
186187
}

0 commit comments

Comments
 (0)