pwa-auth 0.0.16 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +76 -4
- package/README.md +133 -84
- package/demo/index.html +118 -0
- package/demo/styles.css +52 -0
- package/images/empty.jpg +0 -0
- package/license +21 -21
- package/npm/THIRD_PARTY_LICENSES.txt +303 -0
- package/npm/pwa-auth.js +306 -0
- package/package.json +51 -39
- package/deploy/store.js +0 -18
- package/deploy/styles-drawer.js +0 -139
- package/deploy/styles-settings.js +0 -57
- package/deploy/styles.js +0 -88
- package/deploy/user-action.js +0 -69
- package/deploy/user-drawer.js +0 -168
- package/deploy/user-functions.js +0 -191
- package/deploy/user-icon.js +0 -106
- package/deploy/user-reducer.js +0 -41
- package/deploy/user-settings.js +0 -427
- package/images/background.svg +0 -23
- package/images/icon-48x48.png +0 -0
- package/images/npm.svg +0 -85
- package/images/npm007.png +0 -0
- package/index.html +0 -111
- package/launch/application-shell.js +0 -95
- package/launch/package-lock.json +0 -3198
- package/launch/package.json +0 -17
- package/manifest.json +0 -44
- package/polymer.json +0 -24
- package/pwa-auth.js +0 -16
- package/src/store.ts +0 -52
- package/src/styles-drawer.ts +0 -143
- package/src/styles-settings.ts +0 -61
- package/src/styles.ts +0 -95
- package/src/user-action.ts +0 -91
- package/src/user-drawer.ts +0 -168
- package/src/user-functions.ts +0 -190
- package/src/user-icon.ts +0 -104
- package/src/user-reducer.ts +0 -91
- package/src/user-settings.ts +0 -421
- package/tsconfig.json +0 -19
package/deploy/user-functions.js
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
@license
|
|
3
|
-
Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
|
|
4
|
-
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
5
|
-
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
6
|
-
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
7
|
-
Code distributed by Google as part of the polymer project is also
|
|
8
|
-
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
9
|
-
*/
|
|
10
|
-
// @ts-check
|
|
11
|
-
import { store } from './store';
|
|
12
|
-
import { setUser, setAuth } from './user-action';
|
|
13
|
-
// updateLogin() & setUser() - Login state
|
|
14
|
-
export const runFirebase = () => {
|
|
15
|
-
return firebase.auth().onAuthStateChanged((firebaseUser) => {
|
|
16
|
-
if (firebaseUser) {
|
|
17
|
-
store.dispatch(setAuth(true));
|
|
18
|
-
store.dispatch(setUser(firebaseUser));
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
store.dispatch(setAuth(false));
|
|
22
|
-
store.dispatch(setUser(firebaseUser));
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
// setAuth() - Login state
|
|
27
|
-
export const authChange = () => {
|
|
28
|
-
return firebase.auth().onAuthStateChanged((firebaseUser) => {
|
|
29
|
-
if (firebaseUser) {
|
|
30
|
-
store.dispatch(setAuth(true));
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
store.dispatch(setAuth(false));
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
// User State
|
|
38
|
-
export const firebaseUser = () => { return firebase.auth().currentUser || "demo"; };
|
|
39
|
-
export const isUser = () => { return !!firebase.auth().currentUser; };
|
|
40
|
-
export const logOut = () => { return firebase.auth().signOut(); }; /* .then( () => { } ).catch( () => { } ) */
|
|
41
|
-
// User Information
|
|
42
|
-
export const firebaseID = () => { return firebase.auth().currentUser.uid || "demo"; };
|
|
43
|
-
export const profileURL = () => { return firebase.auth().currentUser.photoURL || '/images/manifest/icon-48x48.png'; };
|
|
44
|
-
export const userName = () => { return firebase.auth().currentUser.displayName; };
|
|
45
|
-
export const userEmail = () => { return firebase.auth().currentUser.email; };
|
|
46
|
-
// Delete
|
|
47
|
-
export const deleteUser = () => { return firebase.auth().currentUser.delete(); }; /* .then( () => { }).catch( () => { }) */
|
|
48
|
-
export const deleteDoc = (collect, item) => { return firestore.collection(collect).doc(item).delete(); };
|
|
49
|
-
// export const storageRef = () => { return firebase.storage.ref(); }
|
|
50
|
-
export const saveMessage = (messageText) => {
|
|
51
|
-
return firebase.firestore().collection('feedback')
|
|
52
|
-
.add({
|
|
53
|
-
name: userName(),
|
|
54
|
-
text: messageText,
|
|
55
|
-
profilePicUrl: profileURL(),
|
|
56
|
-
timestamp: firebase.firestore.FieldValue.serverTimestamp()
|
|
57
|
-
}).catch((error) => {
|
|
58
|
-
console.error('Error writing message', error);
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
export const saveImage = () => {
|
|
62
|
-
// 1 - We add a message with a loading icon that will get updated with the shared image.
|
|
63
|
-
firebase.firestore().collection('messages').add({
|
|
64
|
-
name: userName(),
|
|
65
|
-
imageUrl: LOADING_IMAGE_URL,
|
|
66
|
-
profilePicUrl: profileURL(),
|
|
67
|
-
timestamp: firebase.firestore.FieldValue.serverTimestamp()
|
|
68
|
-
}).then((messageRef) => {
|
|
69
|
-
// 2 - Upload the image to Cloud Storage.
|
|
70
|
-
const filePath = firebase.auth().currentUser.uid + '/' + messageRef.id + '/' + file.name;
|
|
71
|
-
return firebase.storage().ref(filePath).put(file).then((fileSnapshot) => {
|
|
72
|
-
// 3 - Generate a public URL for the file.
|
|
73
|
-
return fileSnapshot.ref.getDownloadURL().then((url) => {
|
|
74
|
-
// 4 - Update the chat message placeholder with the image’s URL.
|
|
75
|
-
return messageRef.update({
|
|
76
|
-
imageUrl: url,
|
|
77
|
-
storageUri: fileSnapshot.metadata.fullPath
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
}).catch((error) => { console.error('There was an error uploading a file to Cloud Storage:', error); });
|
|
82
|
-
};
|
|
83
|
-
export const deviceToken = () => {
|
|
84
|
-
// Saves the messaging device token to the datastore.
|
|
85
|
-
firebase.messaging().getToken().then((currentToken) => {
|
|
86
|
-
if (currentToken) {
|
|
87
|
-
console.log('Got FCM device token:', currentToken);
|
|
88
|
-
// Saving the Device Token to the datastore.
|
|
89
|
-
firebase.firestore().collection('fcmTokens').doc(currentToken)
|
|
90
|
-
.set({ uid: firebase.auth().currentUser.uid });
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
// Need to request permissions to show notifications.
|
|
94
|
-
requestNotificationsPermissions();
|
|
95
|
-
}
|
|
96
|
-
}).catch((error) => { console.error('Unable to get messaging token.', error); });
|
|
97
|
-
};
|
|
98
|
-
export const signUp = () => {
|
|
99
|
-
const email = this.shadowRoot.getElementById('txtEmail').value;
|
|
100
|
-
const pass = this.shadowRoot.getElementById('txtPassword').value;
|
|
101
|
-
if (email.length < 4) {
|
|
102
|
-
alert('Please enter an email address.');
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
if (pass.length < 4) {
|
|
106
|
-
alert('Please enter a password.');
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
firebase.auth().createUserWithEmailAndPassword(email, pass).catch((error) => {
|
|
110
|
-
const errorCode = error.code;
|
|
111
|
-
const errorMessage = error.message;
|
|
112
|
-
// [START_EXCLUDE]
|
|
113
|
-
if (errorCode == 'auth/weak-password') {
|
|
114
|
-
alert('The password is too weak.');
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
alert(errorMessage);
|
|
118
|
-
}
|
|
119
|
-
console.log(error);
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
export const anon = () => {
|
|
123
|
-
if (firebase.auth().currentUser) {
|
|
124
|
-
// [START signout]
|
|
125
|
-
firebase.auth().signOut();
|
|
126
|
-
// [END signout]
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
// [START authanon]
|
|
130
|
-
firebase.auth().signInAnonymously().catch((error) => {
|
|
131
|
-
// Handle Errors here.
|
|
132
|
-
const errorCode = error.code;
|
|
133
|
-
const errorMessage = error.message;
|
|
134
|
-
// [START_EXCLUDE]
|
|
135
|
-
if (errorCode === 'auth/operation-not-allowed') {
|
|
136
|
-
alert('You must enable Anonymous auth in the Firebase Console.');
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
console.error(error);
|
|
140
|
-
}
|
|
141
|
-
// [END_EXCLUDE]
|
|
142
|
-
});
|
|
143
|
-
// [END authanon]
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
export const google = () => {
|
|
147
|
-
const provider = new firebase.auth.GoogleAuthProvider();
|
|
148
|
-
provider.addScope('profile');
|
|
149
|
-
provider.addScope('email');
|
|
150
|
-
firebase.auth().signInWithRedirect(provider);
|
|
151
|
-
firebase.auth().getRedirectResult().then((result) => {
|
|
152
|
-
if (result.credential) {
|
|
153
|
-
// This gives you a Google Access Token. You can use it to access the Google API.
|
|
154
|
-
const token = result.credential.accessToken;
|
|
155
|
-
console.log("Google Token");
|
|
156
|
-
}
|
|
157
|
-
// The signed-in user info.
|
|
158
|
-
const firebaseUser = result.firebaseUser;
|
|
159
|
-
}).catch((error) => {
|
|
160
|
-
// Handle Errors here.
|
|
161
|
-
const errorCode = error.code;
|
|
162
|
-
const errorMessage = error.message;
|
|
163
|
-
const email = error.email;
|
|
164
|
-
const credential = error.credential;
|
|
165
|
-
});
|
|
166
|
-
};
|
|
167
|
-
// window.onerror = function(message, file, line, col, error){ console.log(arguments); }
|
|
168
|
-
/*
|
|
169
|
-
// Load Feed
|
|
170
|
-
export const loadMessages = () => {
|
|
171
|
-
// Referance Document Query
|
|
172
|
-
const query = firebase.firestore().collection('messages').orderBy('timestamp', 'desc').limit(12);
|
|
173
|
-
// Start listening to the query.
|
|
174
|
-
query.onSnapshot( (snapshot) => {
|
|
175
|
-
snapshot.docChanges().forEach( (change) => {
|
|
176
|
-
if (change.type === 'removed') {
|
|
177
|
-
// deleteMessage(change.doc.id);
|
|
178
|
-
} else {
|
|
179
|
-
var message = change.doc.data();
|
|
180
|
-
console.log(
|
|
181
|
-
change.doc.id,
|
|
182
|
-
message.timestamp,
|
|
183
|
-
message.name,
|
|
184
|
-
message.text,
|
|
185
|
-
message.profileURL,
|
|
186
|
-
message.imageUrl);
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
};
|
|
191
|
-
*/
|
package/deploy/user-icon.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
@license
|
|
3
|
-
Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
|
|
4
|
-
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
5
|
-
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
6
|
-
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
7
|
-
Code distributed by Google as part of the polymer project is also
|
|
8
|
-
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
9
|
-
*/
|
|
10
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
11
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
12
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
13
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
14
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
15
|
-
};
|
|
16
|
-
import { html, LitElement, css, customElement, property } from 'lit-element';
|
|
17
|
-
import { connect } from 'pwa-helpers/connect-mixin.js';
|
|
18
|
-
import { store } from './store';
|
|
19
|
-
import { userStyles } from './styles';
|
|
20
|
-
import { openSign, setImage } from './user-action';
|
|
21
|
-
import { profileURL } from './user-functions';
|
|
22
|
-
export const faceIcon = html `<svg viewBox="0 0 24 24" height="32px" width="32px"><path d="M9 11.75c-.69 0-1.25.56-1.25 1.25s.56 1.25 1.25 1.25 1.25-.56 1.25-1.25-.56-1.25-1.25-1.25zm6 0c-.69 0-1.25.56-1.25 1.25s.56 1.25 1.25 1.25 1.25-.56 1.25-1.25-.56-1.25-1.25-1.25zM12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8 0-.29.02-.58.05-.86 2.36-1.05 4.23-2.98 5.21-5.37C11.07 8.33 14.05 10 17.42 10c.78 0 1.53-.09 2.25-.26.21.71.33 1.47.33 2.26 0 4.41-3.59 8-8 8z"></path></svg>`;
|
|
23
|
-
let UserIcon = class UserIcon extends connect(store)(LitElement) {
|
|
24
|
-
constructor() {
|
|
25
|
-
super();
|
|
26
|
-
this._user = false;
|
|
27
|
-
this._photoURL = '';
|
|
28
|
-
}
|
|
29
|
-
firstUpdated() {
|
|
30
|
-
this.shadowRoot.getElementById('subscribe').addEventListener('click', () => { store.dispatch(openSign()); });
|
|
31
|
-
// @ts-ignore
|
|
32
|
-
firebase.auth().onAuthStateChanged((firebaseUser) => {
|
|
33
|
-
if (firebaseUser) { /* INCLUDE */
|
|
34
|
-
this._photoURL = profileURL();
|
|
35
|
-
}
|
|
36
|
-
else { /* EXCLUDE */ }
|
|
37
|
-
store.dispatch(setImage(this._photoURL));
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
stateChanged(state) {
|
|
41
|
-
this._user = state.user.currentUser;
|
|
42
|
-
this._photoURL = state.user.photoURL;
|
|
43
|
-
}
|
|
44
|
-
static get styles() {
|
|
45
|
-
return [
|
|
46
|
-
userStyles,
|
|
47
|
-
css `
|
|
48
|
-
:host { margin: auto; display: block; }
|
|
49
|
-
|
|
50
|
-
#subscribe:hover { background-color: lightgrey; }
|
|
51
|
-
#subscribe {
|
|
52
|
-
display: block;
|
|
53
|
-
margin: auto;
|
|
54
|
-
padding: 0;
|
|
55
|
-
background: #fff;
|
|
56
|
-
border-radius: 50%;
|
|
57
|
-
clip-path: circle(50%);
|
|
58
|
-
overflow: hidden;
|
|
59
|
-
width: 36px;
|
|
60
|
-
height: 36px;
|
|
61
|
-
}
|
|
62
|
-
userImage {object-fit: cover;}
|
|
63
|
-
.iconArea {
|
|
64
|
-
border-radius: 50%;
|
|
65
|
-
overflow: hidden;
|
|
66
|
-
width: 32px;
|
|
67
|
-
height: 32px;
|
|
68
|
-
margin: auto;
|
|
69
|
-
}
|
|
70
|
-
svg{ margin:auto;}
|
|
71
|
-
`
|
|
72
|
-
];
|
|
73
|
-
}
|
|
74
|
-
render() {
|
|
75
|
-
return html `
|
|
76
|
-
|
|
77
|
-
<button id="subscribe" aria-label="login">
|
|
78
|
-
${this._user
|
|
79
|
-
? html `
|
|
80
|
-
<div class="iconArea">
|
|
81
|
-
<input
|
|
82
|
-
type="image"
|
|
83
|
-
class="userImage"
|
|
84
|
-
id="image"
|
|
85
|
-
alt="Login"
|
|
86
|
-
height="32px"
|
|
87
|
-
width="32px"
|
|
88
|
-
src="${this._photoURL}">
|
|
89
|
-
</div>
|
|
90
|
-
`
|
|
91
|
-
: html `${faceIcon}`}
|
|
92
|
-
</button>
|
|
93
|
-
|
|
94
|
-
`;
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
__decorate([
|
|
98
|
-
property({ type: Boolean })
|
|
99
|
-
], UserIcon.prototype, "_user", void 0);
|
|
100
|
-
__decorate([
|
|
101
|
-
property({ type: String })
|
|
102
|
-
], UserIcon.prototype, "_photoURL", void 0);
|
|
103
|
-
UserIcon = __decorate([
|
|
104
|
-
customElement('user-icon')
|
|
105
|
-
], UserIcon);
|
|
106
|
-
export { UserIcon };
|
package/deploy/user-reducer.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
@license
|
|
3
|
-
Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
|
|
4
|
-
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
5
|
-
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
6
|
-
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
7
|
-
Code distributed by Google as part of the polymer project is also
|
|
8
|
-
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
9
|
-
*/
|
|
10
|
-
import { OPEN_SIGN, CLOSE_SIGN, SIGN_UP_OPEN, SIGN_UP_CLOSE, LOGGED_IN, SETTINGS_PAGE, SET_USER, SET_IMAGE, SET_NAME
|
|
11
|
-
// PROFILE_TYPE,
|
|
12
|
-
} from './user-action';
|
|
13
|
-
const start = {
|
|
14
|
-
snackState: false,
|
|
15
|
-
// logged: false,
|
|
16
|
-
register: true,
|
|
17
|
-
settings: 'profile',
|
|
18
|
-
currentUser: false,
|
|
19
|
-
setUser: "user",
|
|
20
|
-
customer: "someone",
|
|
21
|
-
name: 'Simon',
|
|
22
|
-
photoURL: 'demo.png',
|
|
23
|
-
phone: '(555) 555-5555',
|
|
24
|
-
email: 'lorium@ipsum.com',
|
|
25
|
-
};
|
|
26
|
-
const user = (state = start, action) => {
|
|
27
|
-
switch (action.type) {
|
|
28
|
-
case OPEN_SIGN: return Object.assign(Object.assign({}, state), { snackState: true });
|
|
29
|
-
case CLOSE_SIGN: return Object.assign(Object.assign({}, state), { snackState: false });
|
|
30
|
-
case SIGN_UP_OPEN: return Object.assign(Object.assign({}, state), { register: true });
|
|
31
|
-
case SIGN_UP_CLOSE: return Object.assign(Object.assign({}, state), { register: false });
|
|
32
|
-
case LOGGED_IN: return Object.assign(Object.assign({}, state), { currentUser: action.currentUser });
|
|
33
|
-
case SETTINGS_PAGE: return Object.assign(Object.assign({}, state), { settings: action.option });
|
|
34
|
-
case SET_USER: return Object.assign(Object.assign({}, state), { setUser: action.user });
|
|
35
|
-
case SET_IMAGE: return Object.assign(Object.assign({}, state), { photoURL: action.image });
|
|
36
|
-
case SET_NAME: return Object.assign(Object.assign({}, state), { customer: action.name });
|
|
37
|
-
// case PROFILE_TYPE: return { ...state, profileChoice: action.profileType};
|
|
38
|
-
default: return state;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
export default user;
|