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.
@@ -1,168 +0,0 @@
1
-
2
-
3
- /**
4
- @license
5
- Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
6
- This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
7
- The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
8
- The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
9
- Code distributed by Google as part of the polymer project is also
10
- subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
11
- */
12
-
13
- // @ts-check
14
-
15
- import { html, LitElement, css, customElement, property } from 'lit-element';
16
- import { connect } from 'pwa-helpers/connect-mixin.js';
17
- import { store, RootState } from './store';
18
- import { userStyles, close } from './styles';
19
- import { User } from './styles-drawer';
20
- import { closeSign, signUp } from './user-action';
21
- import { logOut, anon, google } from './user-functions';
22
-
23
- @customElement('user-drawer')
24
- export class UserDrawer extends connect(store)(LitElement) {
25
-
26
- @property({type: Boolean})
27
- private _log = false;
28
-
29
- @property({type: Boolean})
30
- private _subscribe = false;
31
-
32
- @property({type: Boolean})
33
- private _sign = false;
34
-
35
- constructor() {
36
- super();
37
- }
38
-
39
- protected firstUpdated() {
40
- this.shadowRoot!.getElementById('close') .addEventListener('click', () => { store.dispatch( closeSign(false) ) } );
41
- this.shadowRoot!.getElementById('or') .addEventListener('click', () => { anon() } );
42
- this.shadowRoot!.getElementById('googleSignIn') .addEventListener('click', () => { google() } );
43
- this.shadowRoot!.getElementById('leave') .addEventListener('click', () => { logOut() } );
44
- this.shadowRoot!.getElementById('log') .addEventListener('click', () => { this._signIn() } );
45
- this.shadowRoot!.getElementById('newUser') .addEventListener('click', () => { this._signUp() } );
46
- this.shadowRoot!.getElementById('new') .addEventListener('click', () => { store.dispatch( signUp() ) } );
47
- }
48
-
49
- stateChanged(state: RootState) {
50
- this._subscribe = state.user!.snackState;
51
- this._log = state.user!.currentUser;
52
- this._sign = state.user!.register;
53
- // this.welcome = state.user.welcome;
54
- }
55
-
56
- private _drawerOpenedChanged(e: Event) {
57
- store.dispatch(updateDrawerState((e.target as AppDrawerElement).opened));
58
- }
59
-
60
- private _signIn() {
61
- const a = this.shadowRoot!.getElementById('logs');
62
- a.addEventListener('click', (e:Event) => { e.preventDefault(); });
63
- // Prevent Form's Page Refresh
64
- const email = this.shadowRoot!.getElementById('txtEmail').value;
65
- const password = this.shadowRoot!.getElementById('txtPassword').value;
66
- // @ts-ignore
67
- firebase.auth().signInWithEmailAndPassword(email, password).catch( (error) => {
68
- const errorCode = error.code;
69
- const errorMessage = error.message;
70
- });
71
- }
72
-
73
- private _signUp() {
74
- const email = this.shadowRoot!.getElementById('newtEmail').value;
75
- const pass = this.shadowRoot!.getElementById('newPassword').value;
76
- if (email.length < 4) {
77
- alert('Please enter an email address.');
78
- return;
79
- }
80
- if (pass.length < 4) {
81
- alert('Please enter a password.');
82
- return;
83
- }
84
- // @ts-ignore
85
- firebase.auth().createUserWithEmailAndPassword(email, pass).catch( (error) => {
86
- const errorCode = error.code;
87
- const errorMessage = error.message;
88
- // [START_EXCLUDE]
89
- if (errorCode == 'auth/weak-password') {
90
- alert('The password is too weak.');
91
- } else {
92
- alert(errorMessage);
93
- }
94
- console.log(error);
95
-
96
- });
97
- }
98
-
99
- static get styles() {
100
- return [
101
- userStyles,
102
- User,
103
- css`
104
- :host {
105
-
106
- }
107
- `
108
- ]}
109
-
110
- protected render() {
111
- return html`
112
-
113
- <!-- Login Wrapper -->
114
- <div class="visibility userDrawer" ?on="${ this._subscribe === true }">
115
-
116
- <div class="exit">
117
- <div></div>
118
- <h3 id="or">${this._log ? html`ACCOUNT` : html`SUBSCRIBE` }</h3>
119
- <button id="close" class="sign-right">${close}</button>
120
- </div>
121
-
122
- <div class="spec" ?on="${ this._log === false }">
123
-
124
- <p><button id="googleSignIn" class="google">
125
- <span class="icon"></span>
126
- <span class="buttonText">Sign in with Google</span>
127
- </button></p>
128
-
129
- <p><button id="new">create a new account</button></p>
130
-
131
- </div>
132
- <!--
133
- <form id="logs" autocomplete="on" class="spec" \?on="\${ this._sign === true }">
134
- <ul>
135
- <li class="inpat">
136
- <label><input id="txtEmail" type="email" >Email</label>
137
- <label><input id="txtPassword" type="Password" >Password</label>
138
- </li>
139
- <li><button id="log" class="action-button">Sign in</button></li>
140
- </ul>
141
- </form>
142
- -->
143
-
144
- <!-- Sign UP
145
- <form id="signup" autocomplete="on" class="spec" \?on="\${ this._sign === false }">
146
- <ul>
147
- <li class="inpat">
148
- <label><input id="newEmail" type="email" >Email</label>
149
- <label><input id="newPassword" type="Password" >Password</label>
150
- <label><input id="verifyEmail" type="email" >Verify Email</label>
151
- <label><input id="veriftPassword" type="Password" >Verify Password</label>
152
- </li>
153
- <li><button id="newUser" class="action-button">Sign up</button></li>
154
- </ul>
155
- </form>
156
- -->
157
-
158
- <!-- Logged IN -->
159
- <div class="spec setLog" ?on="${ this._log === true }">
160
- <slot></slot>
161
- <p><a href="/settings">Settings</a></p>
162
- <p><a id="leave" aria-label="log out">log out</a></p>
163
- </div>
164
-
165
- </div>
166
- `;
167
- }
168
- }
@@ -1,190 +0,0 @@
1
-
2
- /**
3
- @license
4
- Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
5
- This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
6
- The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
7
- The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
8
- Code distributed by Google as part of the polymer project is also
9
- subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
10
- */
11
-
12
- // @ts-check
13
- import { store } from './store';
14
- import { setUser, setAuth } from './user-action';
15
-
16
- // updateLogin() & setUser() - Login state
17
- export const runFirebase = () => {
18
- return firebase.auth().onAuthStateChanged( (firebaseUser) => {
19
- if (firebaseUser) { store.dispatch(setAuth(true)); store.dispatch(setUser(firebaseUser)); }
20
- else { store.dispatch(setAuth(false)); store.dispatch(setUser(firebaseUser)); }
21
- });
22
- };
23
-
24
- // setAuth() - Login state
25
- export const authChange = () => {
26
- return firebase.auth().onAuthStateChanged( (firebaseUser) => {
27
- if (firebaseUser) { store.dispatch( setAuth(true) )}
28
- else { store.dispatch( setAuth(false) )}
29
- });
30
- }
31
-
32
- // User State
33
- export const firebaseUser = () => { return firebase.auth().currentUser || "demo"; };
34
- export const isUser = () => { return !!firebase.auth().currentUser; };
35
- export const logOut = () => { return firebase.auth().signOut(); }; /* .then( () => { } ).catch( () => { } ) */
36
-
37
- // User Information
38
- export const firebaseID = () => { return firebase.auth().currentUser.uid || "demo" ; };
39
- export const profileURL = () => { return firebase.auth().currentUser.photoURL || '/images/manifest/icon-48x48.png'; };
40
- export const userName = () => { return firebase.auth().currentUser.displayName; };
41
- export const userEmail = () => { return firebase.auth().currentUser.email; };
42
-
43
- // Delete
44
- export const deleteUser = () => { return firebase.auth().currentUser.delete() }; /* .then( () => { }).catch( () => { }) */
45
- export const deleteDoc = (collect, item) => { return firestore.collection(collect).doc(item).delete() };
46
- // export const storageRef = () => { return firebase.storage.ref(); }
47
-
48
- export const saveMessage = (messageText) => {
49
- return firebase.firestore().collection('feedback')
50
- .add({
51
- name: userName(),
52
- text: messageText,
53
- profilePicUrl: profileURL(),
54
- timestamp: firebase.firestore.FieldValue.serverTimestamp()
55
- }).catch( (error) => {
56
- console.error('Error writing message', error);
57
- });
58
- };
59
-
60
- export const saveImage = () => {
61
- // 1 - We add a message with a loading icon that will get updated with the shared image.
62
- firebase.firestore().collection('messages').add({
63
- name: userName(),
64
- imageUrl: LOADING_IMAGE_URL,
65
- profilePicUrl: profileURL(),
66
- timestamp: firebase.firestore.FieldValue.serverTimestamp()
67
- }).then( (messageRef) => {
68
- // 2 - Upload the image to Cloud Storage.
69
- const filePath = firebase.auth().currentUser.uid + '/' + messageRef.id + '/' + file.name;
70
- return firebase.storage().ref(filePath).put(file).then( (fileSnapshot) => {
71
- // 3 - Generate a public URL for the file.
72
- return fileSnapshot.ref.getDownloadURL().then((url) => {
73
- // 4 - Update the chat message placeholder with the image’s URL.
74
- return messageRef.update({
75
- imageUrl: url,
76
- storageUri: fileSnapshot.metadata.fullPath
77
- });
78
- });
79
- });
80
- }).catch( (error) => { console.error('There was an error uploading a file to Cloud Storage:', error); });
81
- };
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
- } else {
92
- // Need to request permissions to show notifications.
93
- requestNotificationsPermissions();
94
- }
95
- }).catch( (error) => { console.error('Unable to get messaging token.', error); });
96
- };
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
- } else {
116
- alert(errorMessage);
117
- }
118
- console.log(error);
119
- });
120
-
121
- }
122
-
123
- export const anon = () => {
124
- if (firebase.auth().currentUser) {
125
- // [START signout]
126
- firebase.auth().signOut();
127
- // [END signout]
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
- } else { console.error(error); }
138
- // [END_EXCLUDE]
139
- });
140
- // [END authanon]
141
- }
142
- };
143
-
144
- export const google = () => {
145
- const provider = new firebase.auth.GoogleAuthProvider();
146
- provider.addScope('profile');
147
- provider.addScope('email');
148
- firebase.auth().signInWithRedirect(provider);
149
- firebase.auth().getRedirectResult().then( (result) => {
150
- if (result.credential) {
151
- // This gives you a Google Access Token. You can use it to access the Google API.
152
- const token = result.credential.accessToken; console.log("Google Token");
153
- }
154
- // The signed-in user info.
155
- const firebaseUser = result.firebaseUser;
156
- }).catch( (error) => {
157
- // Handle Errors here.
158
- const errorCode = error.code;
159
- const errorMessage = error.message;
160
- const email = error.email;
161
- const credential = error.credential;
162
- });
163
- };
164
-
165
- // window.onerror = function(message, file, line, col, error){ console.log(arguments); }
166
-
167
- /*
168
- // Load Feed
169
- export const loadMessages = () => {
170
- // Referance Document Query
171
- const query = firebase.firestore().collection('messages').orderBy('timestamp', 'desc').limit(12);
172
- // Start listening to the query.
173
- query.onSnapshot( (snapshot) => {
174
- snapshot.docChanges().forEach( (change) => {
175
- if (change.type === 'removed') {
176
- // deleteMessage(change.doc.id);
177
- } else {
178
- var message = change.doc.data();
179
- console.log(
180
- change.doc.id,
181
- message.timestamp,
182
- message.name,
183
- message.text,
184
- message.profileURL,
185
- message.imageUrl);
186
- }
187
- });
188
- });
189
- };
190
- */
package/src/user-icon.ts DELETED
@@ -1,104 +0,0 @@
1
-
2
- /**
3
- @license
4
- Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
5
- This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
6
- The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
7
- The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
8
- Code distributed by Google as part of the polymer project is also
9
- subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
10
- */
11
-
12
- import { html, LitElement, css, customElement, property } from 'lit-element';
13
- import { connect } from 'pwa-helpers/connect-mixin.js';
14
- import { store, RootState } from './store';
15
- import { userStyles } from './styles';
16
- import { openSign, setImage } from './user-action';
17
- import { profileURL } from './user-functions';
18
-
19
- 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>`;
20
-
21
- @customElement('user-icon')
22
- export class UserIcon extends connect(store)(LitElement) {
23
-
24
- @property({type: Boolean})
25
- private _user = false;
26
-
27
- @property({type: String})
28
- private _photoURL = '';
29
-
30
-
31
- constructor() {
32
- super();
33
- }
34
-
35
- protected firstUpdated() {
36
- this.shadowRoot!.getElementById('subscribe').addEventListener('click', () => { store.dispatch(openSign()) } );
37
-
38
- // @ts-ignore
39
- firebase.auth().onAuthStateChanged( (firebaseUser) => {
40
- if (firebaseUser) { /* INCLUDE */ this._photoURL = profileURL(); }
41
- else { /* EXCLUDE */ }
42
- store.dispatch( setImage( this._photoURL ) );
43
- });
44
- }
45
-
46
- stateChanged(state: RootState) {
47
- this._user = state.user!.currentUser;
48
- this._photoURL = state.user!.photoURL;
49
- }
50
-
51
-
52
- static get styles() {
53
- return [
54
- userStyles,
55
- css`
56
- :host { margin: auto; display: block; }
57
-
58
- #subscribe:hover { background-color: lightgrey; }
59
- #subscribe {
60
- display: block;
61
- margin: auto;
62
- padding: 0;
63
- background: #fff;
64
- border-radius: 50%;
65
- clip-path: circle(50%);
66
- overflow: hidden;
67
- width: 36px;
68
- height: 36px;
69
- }
70
- userImage {object-fit: cover;}
71
- .iconArea {
72
- border-radius: 50%;
73
- overflow: hidden;
74
- width: 32px;
75
- height: 32px;
76
- margin: auto;
77
- }
78
- svg{ margin:auto;}
79
- `
80
- ]}
81
-
82
- protected render() {
83
- return html`
84
-
85
- <button id="subscribe" aria-label="login">
86
- ${this._user
87
- ? html`
88
- <div class="iconArea">
89
- <input
90
- type="image"
91
- class="userImage"
92
- id="image"
93
- alt="Login"
94
- height="32px"
95
- width="32px"
96
- src="${this._photoURL}">
97
- </div>
98
- `
99
- : html`${faceIcon}` }
100
- </button>
101
-
102
- `;
103
- }
104
- }
@@ -1,91 +0,0 @@
1
-
2
-
3
- /**
4
- @license
5
- Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
6
- This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
7
- The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
8
- The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
9
- Code distributed by Google as part of the polymer project is also
10
- subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
11
- */
12
-
13
- import { Reducer } from 'redux';
14
- import { RootAction } from './store';
15
- import {
16
- OPEN_SIGN,
17
- CLOSE_SIGN,
18
-
19
- SIGN_UP_OPEN,
20
- SIGN_UP_CLOSE,
21
-
22
- LOGGED_IN,
23
- SETTINGS_PAGE,
24
-
25
- SET_USER,
26
- SET_IMAGE,
27
- SET_NAME
28
-
29
- // PROFILE_TYPE,
30
- } from './user-action';
31
-
32
- export interface AppState {
33
- snackState: boolean,
34
- // logged: boolean
35
- register: boolean,
36
- settings: string,
37
-
38
- currentUser: boolean,
39
- setUser: string,
40
- customer: string
41
-
42
- name: string,
43
- photoURL: string,
44
- phone: string,
45
- email: string
46
-
47
- // profileChoice: string,
48
- }
49
-
50
- const start: AppState = {
51
- snackState: false,
52
- // logged: false,
53
- register: true,
54
- settings: 'profile',
55
-
56
- currentUser: false,
57
- setUser: "user",
58
- customer: "someone",
59
-
60
- name: 'Simon',
61
- photoURL: 'demo.png',
62
- phone: '(555) 555-5555',
63
- email: 'lorium@ipsum.com',
64
-
65
- // profileChoice: 'unChosen',
66
- };
67
-
68
- const user: Reducer<AppState, RootAction> = ( state = start, action ) => {
69
- switch ( action.type ) {
70
-
71
- case OPEN_SIGN: return { ...state, snackState: true };
72
- case CLOSE_SIGN: return { ...state, snackState: false };
73
-
74
- case SIGN_UP_OPEN: return { ...state, register: true };
75
- case SIGN_UP_CLOSE: return { ...state, register: false };
76
-
77
- case LOGGED_IN: return { ...state, currentUser: action.currentUser };
78
- case SETTINGS_PAGE: return { ...state, settings: action.option };
79
-
80
- case SET_USER: return { ...state, setUser: action.user };
81
- case SET_IMAGE: return { ...state, photoURL: action.image };
82
- case SET_NAME: return { ...state, customer: action.name };
83
-
84
- // case PROFILE_TYPE: return { ...state, profileChoice: action.profileType};
85
-
86
- default: return state;
87
-
88
- }
89
- }
90
-
91
- export default user;