pwa-auth 0.0.15 → 1.1.3
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 +113 -83
- package/demo/index.html +93 -101
- package/demo/styles.css +52 -0
- package/images/empty.jpg +0 -0
- package/images/favicon.ico +0 -0
- package/images/manifest/logo-144.png +0 -0
- package/images/manifest/logo-192.png +0 -0
- package/images/manifest/logo-48.png +0 -0
- package/images/manifest/logo-512.png +0 -0
- package/images/manifest/logo-72.png +0 -0
- package/images/manifest/logo-96.png +0 -0
- package/images/manifest/maskable_icon_x128.png +0 -0
- package/images/manifest/maskable_icon_x192.png +0 -0
- package/images/manifest/maskable_icon_x384.png +0 -0
- package/images/manifest/maskable_icon_x48.png +0 -0
- package/images/manifest/maskable_icon_x512.png +0 -0
- package/images/manifest/maskable_icon_x72.png +0 -0
- package/images/manifest/maskable_icon_x96.png +0 -0
- package/images/npm.svg +85 -85
- package/license +21 -21
- package/manifest.json +47 -44
- package/npm/pwa-auth.js +3163 -0
- package/npm/pwa-auth.js.map +1 -0
- package/package.json +50 -38
- 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 -163
- package/deploy/user-functions.js +0 -175
- package/deploy/user-icon.js +0 -107
- package/deploy/user-reducer.js +0 -41
- package/deploy/user-settings.js +0 -418
- package/polymer.json +0 -24
- package/pwa-auth.js +0 -16
- package/robots.txt +0 -2
- 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 -162
- package/src/user-functions.ts +0 -173
- package/src/user-icon.ts +0 -106
- package/src/user-reducer.ts +0 -91
- package/src/user-settings.ts +0 -402
- package/tsconfig.json +0 -19
- package/webpack.config.js +0 -72
package/deploy/user-functions.js
DELETED
|
@@ -1,175 +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
|
-
// export const runList = () => { firebase.auth().onAuthStateChanged( (firebaseUser) => { if (firebaseUser) { store.dispatch(setList(firebaseUser)); } else { store.dispatch(setList(firebaseUser)); } }); };
|
|
14
|
-
export const runFirebase = () => {
|
|
15
|
-
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
|
-
export const authChange = () => { return firebase.auth().onAuthStateChanged((firebaseUser) => { if (firebaseUser) {
|
|
27
|
-
store.dispatch(setAuth(true));
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
store.dispatch(setAuth(false));
|
|
31
|
-
} }); };
|
|
32
|
-
export const firebaseUser = () => { return firebase.auth().currentUser || "demo"; };
|
|
33
|
-
export const firebaseID = () => { return firebase.auth().currentUser.uid || "demo"; };
|
|
34
|
-
export const logOut = () => { return firebase.auth().signOut(); }; /* .then( () => { } ).catch( () => { } ) */
|
|
35
|
-
export const isUser = () => { return !!firebase.auth().currentUser; };
|
|
36
|
-
export const profileURL = () => { return firebase.auth().currentUser.photoURL || '/images/manifest/icon-48x48.png'; };
|
|
37
|
-
export const userName = () => { return firebase.auth().currentUser.displayName; };
|
|
38
|
-
export const userEmail = () => { return firebase.auth().currentUser.email; };
|
|
39
|
-
export const deleteUser = () => { return firebase.auth().currentUser.delete(); }; /* .then( () => { }).catch( () => { }) */
|
|
40
|
-
export const deleteDoc = (collect, item) => { return firestore.collection(collect).doc(item).delete(); };
|
|
41
|
-
// export const storageRef = () => { return firebase.storage.ref(); }
|
|
42
|
-
export const saveMessage = (messageText) => {
|
|
43
|
-
return firebase.firestore().collection('feedback')
|
|
44
|
-
.add({
|
|
45
|
-
name: userName(),
|
|
46
|
-
text: messageText,
|
|
47
|
-
profilePicUrl: profileURL(),
|
|
48
|
-
timestamp: firebase.firestore.FieldValue.serverTimestamp()
|
|
49
|
-
}).catch((error) => { console.error('Error writing new message to Firebase Database', error); });
|
|
50
|
-
};
|
|
51
|
-
export const loadMessages = () => {
|
|
52
|
-
// Create the query to load the last 12 messages and listen for new ones.
|
|
53
|
-
const query = firebase.firestore().collection('messages').orderBy('timestamp', 'desc').limit(12);
|
|
54
|
-
// Start listening to the query.
|
|
55
|
-
query.onSnapshot((snapshot) => {
|
|
56
|
-
snapshot.docChanges().forEach((change) => {
|
|
57
|
-
if (change.type === 'removed') {
|
|
58
|
-
// deleteMessage(change.doc.id);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
var message = change.doc.data();
|
|
62
|
-
console.log(change.doc.id, message.timestamp, message.name, message.text, message.profileURL, message.imageUrl);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
export const saveImage = () => {
|
|
68
|
-
// 1 - We add a message with a loading icon that will get updated with the shared image.
|
|
69
|
-
firebase.firestore().collection('messages').add({
|
|
70
|
-
name: userName(),
|
|
71
|
-
imageUrl: LOADING_IMAGE_URL,
|
|
72
|
-
profilePicUrl: profileURL(),
|
|
73
|
-
timestamp: firebase.firestore.FieldValue.serverTimestamp()
|
|
74
|
-
}).then((messageRef) => {
|
|
75
|
-
// 2 - Upload the image to Cloud Storage.
|
|
76
|
-
const filePath = firebase.auth().currentUser.uid + '/' + messageRef.id + '/' + file.name;
|
|
77
|
-
return firebase.storage().ref(filePath).put(file).then((fileSnapshot) => {
|
|
78
|
-
// 3 - Generate a public URL for the file.
|
|
79
|
-
return fileSnapshot.ref.getDownloadURL().then((url) => {
|
|
80
|
-
// 4 - Update the chat message placeholder with the image’s URL.
|
|
81
|
-
return messageRef.update({
|
|
82
|
-
imageUrl: url,
|
|
83
|
-
storageUri: fileSnapshot.metadata.fullPath
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
}).catch((error) => { console.error('There was an error uploading a file to Cloud Storage:', error); });
|
|
88
|
-
};
|
|
89
|
-
export const deviceToken = () => {
|
|
90
|
-
// Saves the messaging device token to the datastore.
|
|
91
|
-
firebase.messaging().getToken().then((currentToken) => {
|
|
92
|
-
if (currentToken) {
|
|
93
|
-
console.log('Got FCM device token:', currentToken);
|
|
94
|
-
// Saving the Device Token to the datastore.
|
|
95
|
-
firebase.firestore().collection('fcmTokens').doc(currentToken)
|
|
96
|
-
.set({ uid: firebase.auth().currentUser.uid });
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
// Need to request permissions to show notifications.
|
|
100
|
-
requestNotificationsPermissions();
|
|
101
|
-
}
|
|
102
|
-
}).catch((error) => { console.error('Unable to get messaging token.', error); });
|
|
103
|
-
};
|
|
104
|
-
export const signUp = () => {
|
|
105
|
-
const email = this.shadowRoot.getElementById('txtEmail').value;
|
|
106
|
-
const pass = this.shadowRoot.getElementById('txtPassword').value;
|
|
107
|
-
if (email.length < 4) {
|
|
108
|
-
alert('Please enter an email address.');
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
if (pass.length < 4) {
|
|
112
|
-
alert('Please enter a password.');
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
firebase.auth().createUserWithEmailAndPassword(email, pass).catch((error) => {
|
|
116
|
-
const errorCode = error.code;
|
|
117
|
-
const errorMessage = error.message;
|
|
118
|
-
// [START_EXCLUDE]
|
|
119
|
-
if (errorCode == 'auth/weak-password') {
|
|
120
|
-
alert('The password is too weak.');
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
alert(errorMessage);
|
|
124
|
-
}
|
|
125
|
-
console.log(error);
|
|
126
|
-
});
|
|
127
|
-
};
|
|
128
|
-
export const anon = () => {
|
|
129
|
-
if (firebase.auth().currentUser) {
|
|
130
|
-
// [START signout]
|
|
131
|
-
firebase.auth().signOut();
|
|
132
|
-
// [END signout]
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
// [START authanon]
|
|
136
|
-
firebase.auth().signInAnonymously().catch((error) => {
|
|
137
|
-
// Handle Errors here.
|
|
138
|
-
const errorCode = error.code;
|
|
139
|
-
const errorMessage = error.message;
|
|
140
|
-
// [START_EXCLUDE]
|
|
141
|
-
if (errorCode === 'auth/operation-not-allowed') {
|
|
142
|
-
alert('You must enable Anonymous auth in the Firebase Console.');
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
console.error(error);
|
|
146
|
-
}
|
|
147
|
-
// [END_EXCLUDE]
|
|
148
|
-
});
|
|
149
|
-
// [END authanon]
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
export const google = () => {
|
|
153
|
-
const provider = new firebase.auth.GoogleAuthProvider();
|
|
154
|
-
provider.addScope('profile');
|
|
155
|
-
provider.addScope('email');
|
|
156
|
-
firebase.auth().signInWithRedirect(provider);
|
|
157
|
-
firebase.auth().getRedirectResult().then((result) => {
|
|
158
|
-
if (result.credential) {
|
|
159
|
-
// This gives you a Google Access Token. You can use it to access the Google API.
|
|
160
|
-
const token = result.credential.accessToken;
|
|
161
|
-
console.log("Google Token");
|
|
162
|
-
}
|
|
163
|
-
// The signed-in user info.
|
|
164
|
-
const firebaseUser = result.firebaseUser;
|
|
165
|
-
}).catch((error) => {
|
|
166
|
-
// Handle Errors here.
|
|
167
|
-
const errorCode = error.code;
|
|
168
|
-
const errorMessage = error.message;
|
|
169
|
-
// The email of the user's account used.
|
|
170
|
-
const email = error.email;
|
|
171
|
-
// The firebase.auth.AuthCredential type that was used.
|
|
172
|
-
const credential = error.credential;
|
|
173
|
-
});
|
|
174
|
-
};
|
|
175
|
-
// window.onerror = function(message, file, line, col, error){ console.log(arguments); }
|
package/deploy/user-icon.js
DELETED
|
@@ -1,107 +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
|
-
// @ts-check
|
|
17
|
-
import { html, LitElement, css, customElement, property } from 'lit-element';
|
|
18
|
-
import { connect } from 'pwa-helpers/connect-mixin.js';
|
|
19
|
-
import { store } from './store';
|
|
20
|
-
import { userStyles } from './styles';
|
|
21
|
-
import { openSign, setImage } from './user-action';
|
|
22
|
-
import { profileURL } from './user-functions';
|
|
23
|
-
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>`;
|
|
24
|
-
let UserIcon = class UserIcon extends connect(store)(LitElement) {
|
|
25
|
-
constructor() {
|
|
26
|
-
super();
|
|
27
|
-
this._user = false;
|
|
28
|
-
this._photoURL = '';
|
|
29
|
-
}
|
|
30
|
-
firstUpdated() {
|
|
31
|
-
this.shadowRoot.getElementById('subscribe').addEventListener('click', () => { store.dispatch(openSign()); });
|
|
32
|
-
// @ts-ignore
|
|
33
|
-
firebase.auth().onAuthStateChanged((firebaseUser) => {
|
|
34
|
-
if (firebaseUser) { /* INCLUDE */
|
|
35
|
-
this._photoURL = profileURL();
|
|
36
|
-
}
|
|
37
|
-
else { /* EXCLUDE */ }
|
|
38
|
-
store.dispatch(setImage(this._photoURL));
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
stateChanged(state) {
|
|
42
|
-
this._user = state.user.currentUser;
|
|
43
|
-
this._photoURL = state.user.photoURL;
|
|
44
|
-
}
|
|
45
|
-
static get styles() {
|
|
46
|
-
return [
|
|
47
|
-
userStyles,
|
|
48
|
-
css `
|
|
49
|
-
:host { margin: auto; display: block; }
|
|
50
|
-
|
|
51
|
-
#subscribe:hover { background-color: lightgrey; }
|
|
52
|
-
#subscribe {
|
|
53
|
-
display: block;
|
|
54
|
-
margin: auto;
|
|
55
|
-
padding: 0;
|
|
56
|
-
background: #fff;
|
|
57
|
-
border-radius: 50%;
|
|
58
|
-
clip-path: circle(50%);
|
|
59
|
-
overflow: hidden;
|
|
60
|
-
width: 36px;
|
|
61
|
-
height: 36px;
|
|
62
|
-
}
|
|
63
|
-
userImage {object-fit: cover;}
|
|
64
|
-
.iconArea {
|
|
65
|
-
border-radius: 50%;
|
|
66
|
-
overflow: hidden;
|
|
67
|
-
width: 32px;
|
|
68
|
-
height: 32px;
|
|
69
|
-
margin: auto;
|
|
70
|
-
}
|
|
71
|
-
svg{ margin:auto;}
|
|
72
|
-
`
|
|
73
|
-
];
|
|
74
|
-
}
|
|
75
|
-
render() {
|
|
76
|
-
return html `
|
|
77
|
-
|
|
78
|
-
<button id="subscribe" aria-label="login">
|
|
79
|
-
${this._user
|
|
80
|
-
? html `
|
|
81
|
-
<div class="iconArea">
|
|
82
|
-
<input
|
|
83
|
-
type="image"
|
|
84
|
-
class="userImage"
|
|
85
|
-
id="image"
|
|
86
|
-
alt="Login"
|
|
87
|
-
height="32px"
|
|
88
|
-
width="32px"
|
|
89
|
-
src="${this._photoURL}">
|
|
90
|
-
</div>
|
|
91
|
-
`
|
|
92
|
-
: html `${faceIcon}`}
|
|
93
|
-
</button>
|
|
94
|
-
|
|
95
|
-
`;
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
__decorate([
|
|
99
|
-
property({ type: Boolean })
|
|
100
|
-
], UserIcon.prototype, "_user", void 0);
|
|
101
|
-
__decorate([
|
|
102
|
-
property({ type: String })
|
|
103
|
-
], UserIcon.prototype, "_photoURL", void 0);
|
|
104
|
-
UserIcon = __decorate([
|
|
105
|
-
customElement('user-icon')
|
|
106
|
-
], UserIcon);
|
|
107
|
-
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({}, state, { snackState: true });
|
|
29
|
-
case CLOSE_SIGN: return Object.assign({}, state, { snackState: false });
|
|
30
|
-
case SIGN_UP_OPEN: return Object.assign({}, state, { register: true });
|
|
31
|
-
case SIGN_UP_CLOSE: return Object.assign({}, state, { register: false });
|
|
32
|
-
case LOGGED_IN: return Object.assign({}, state, { currentUser: action.currentUser });
|
|
33
|
-
case SETTINGS_PAGE: return Object.assign({}, state, { settings: action.option });
|
|
34
|
-
case SET_USER: return Object.assign({}, state, { setUser: action.user });
|
|
35
|
-
case SET_IMAGE: return Object.assign({}, state, { photoURL: action.image });
|
|
36
|
-
case SET_NAME: return 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;
|