pwa-auth 2.0.4 → 2.0.5

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.
Files changed (120) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/README.md +54 -34
  3. package/demo/index.html +22 -126
  4. package/demo/pwa-styles.css +77 -0
  5. package/deploy/css/font.d.ts.map +1 -1
  6. package/deploy/css/form/button.d.ts.map +1 -1
  7. package/deploy/css/form/input.d.ts.map +1 -1
  8. package/deploy/css/form/label.d.ts.map +1 -1
  9. package/deploy/css/form/list.d.ts.map +1 -1
  10. package/deploy/css/svg.d.ts.map +1 -1
  11. package/deploy/css/toggle.d.ts.map +1 -1
  12. package/deploy/custom-elements/drawer/css/drawer.d.ts.map +1 -1
  13. package/deploy/custom-elements/drawer/css/exit.d.ts.map +1 -1
  14. package/deploy/custom-elements/drawer/css/link.d.ts.map +1 -1
  15. package/deploy/custom-elements/drawer/css/paragraph.d.ts.map +1 -1
  16. package/deploy/custom-elements/drawer/css/toggle.d.ts.map +1 -1
  17. package/deploy/custom-elements/drawer/drawer.d.ts.map +1 -1
  18. package/deploy/custom-elements/drawer/drawer.js +1 -1
  19. package/deploy/custom-elements/drawer/input/forgot.d.ts.map +1 -1
  20. package/deploy/custom-elements/drawer/input/forgot.js +1 -1
  21. package/deploy/custom-elements/drawer/input/login.d.ts.map +1 -1
  22. package/deploy/custom-elements/drawer/input/login.js +1 -1
  23. package/deploy/custom-elements/drawer/input/sign-up.d.ts.map +1 -1
  24. package/deploy/custom-elements/drawer/input/sign-up.js +1 -1
  25. package/deploy/custom-elements/icon/css/icon.d.ts.map +1 -1
  26. package/deploy/custom-elements/icon/css/icon.js +0 -1
  27. package/deploy/custom-elements/icon/icon.d.ts.map +1 -1
  28. package/deploy/custom-elements/settings/css/navigation.d.ts.map +1 -1
  29. package/deploy/custom-elements/settings/input/delete.d.ts.map +1 -1
  30. package/deploy/custom-elements/settings/input/delete.js +1 -1
  31. package/deploy/custom-elements/settings/input/email.d.ts.map +1 -1
  32. package/deploy/custom-elements/settings/input/email.js +1 -1
  33. package/deploy/custom-elements/settings/input/images.d.ts.map +1 -1
  34. package/deploy/custom-elements/settings/input/images.js +1 -1
  35. package/deploy/custom-elements/settings/input/name.d.ts.map +1 -1
  36. package/deploy/custom-elements/settings/input/name.js +1 -1
  37. package/deploy/custom-elements/settings/input/password.d.ts.map +1 -1
  38. package/deploy/custom-elements/settings/input/password.js +1 -1
  39. package/deploy/custom-elements/settings/input/uploader.d.ts +0 -2
  40. package/deploy/custom-elements/settings/input/uploader.d.ts.map +1 -1
  41. package/deploy/custom-elements/settings/input/uploader.js +11 -22
  42. package/deploy/custom-elements/settings/settings.d.ts.map +1 -1
  43. package/deploy/firebase/firebase-login.d.ts +21 -0
  44. package/deploy/firebase/firebase-login.d.ts.map +1 -0
  45. package/deploy/firebase/firebase-login.js +85 -0
  46. package/deploy/firebase/firebase.d.ts +20 -0
  47. package/deploy/firebase/firebase.d.ts.map +1 -0
  48. package/deploy/firebase/firebase.js +76 -0
  49. package/deploy/firebase/start.d.ts.map +1 -0
  50. package/deploy/{start.js → firebase/start.js} +5 -4
  51. package/deploy/lazy-loader.d.ts.map +1 -1
  52. package/deploy/redux/backend.d.ts.map +1 -1
  53. package/deploy/redux/drawer.d.ts.map +1 -1
  54. package/deploy/redux/frontend.d.ts.map +1 -1
  55. package/deploy/redux/object.d.ts.map +1 -1
  56. package/deploy/store.d.ts.map +1 -1
  57. package/npm/pwa-auth.js +1 -1
  58. package/package.json +4 -3
  59. package/source/css/font.ts +17 -0
  60. package/source/css/form/button.ts +55 -0
  61. package/source/css/form/input.ts +25 -0
  62. package/source/css/form/label.ts +25 -0
  63. package/source/css/form/list.ts +23 -0
  64. package/source/css/svg.ts +5 -0
  65. package/source/css/toggle.ts +9 -0
  66. package/source/custom-elements/drawer/css/drawer.ts +64 -0
  67. package/source/custom-elements/drawer/css/exit.ts +49 -0
  68. package/source/custom-elements/drawer/css/link.ts +15 -0
  69. package/source/custom-elements/drawer/css/paragraph.ts +11 -0
  70. package/source/custom-elements/drawer/css/toggle.ts +19 -0
  71. package/source/custom-elements/drawer/drawer.ts +120 -0
  72. package/source/custom-elements/drawer/input/forgot.ts +121 -0
  73. package/source/custom-elements/drawer/input/login.ts +135 -0
  74. package/source/custom-elements/drawer/input/sign-up.ts +158 -0
  75. package/source/custom-elements/icon/css/icon.ts +70 -0
  76. package/source/custom-elements/icon/icon.ts +87 -0
  77. package/source/custom-elements/settings/css/navigation.ts +92 -0
  78. package/source/custom-elements/settings/input/delete.ts +83 -0
  79. package/source/custom-elements/settings/input/email.ts +135 -0
  80. package/source/custom-elements/settings/input/images.ts +57 -0
  81. package/source/custom-elements/settings/input/name.ts +99 -0
  82. package/source/custom-elements/settings/input/password.ts +156 -0
  83. package/source/custom-elements/settings/input/uploader.ts +326 -0
  84. package/source/custom-elements/settings/settings.ts +202 -0
  85. package/source/firebase/firebase-login.ts +246 -0
  86. package/source/firebase/firebase.ts +214 -0
  87. package/source/firebase/start.ts +216 -0
  88. package/source/lazy-loader.ts +20 -0
  89. package/source/redux/backend.ts +94 -0
  90. package/source/redux/drawer.ts +37 -0
  91. package/source/redux/frontend.ts +134 -0
  92. package/source/redux/object.ts +31 -0
  93. package/source/store.ts +19 -0
  94. package/website/404.html +33 -0
  95. package/website/THIRD_PARTY_LICENSES.txt +303 -0
  96. package/website/css/pwa-styles.css +36 -0
  97. package/website/css/styles.css +67 -0
  98. package/website/images/empty.jpg +0 -0
  99. package/website/images/favicon.ico +0 -0
  100. package/website/images/manifest/logo-144.png +0 -0
  101. package/website/images/manifest/logo-192.png +0 -0
  102. package/website/images/manifest/logo-48.png +0 -0
  103. package/website/images/manifest/logo-512.png +0 -0
  104. package/website/images/manifest/logo-72.png +0 -0
  105. package/website/images/manifest/logo-96.png +0 -0
  106. package/website/images/manifest/maskable_icon_x128.png +0 -0
  107. package/website/images/manifest/maskable_icon_x192.png +0 -0
  108. package/website/images/manifest/maskable_icon_x384.png +0 -0
  109. package/website/images/manifest/maskable_icon_x48.png +0 -0
  110. package/website/images/manifest/maskable_icon_x512.png +0 -0
  111. package/website/images/manifest/maskable_icon_x72.png +0 -0
  112. package/website/images/manifest/maskable_icon_x96.png +0 -0
  113. package/website/index.html +64 -0
  114. package/website/js/pwa-auth.js +306 -0
  115. package/website/sitemap.xml +11 -0
  116. package/deploy/interface.d.ts +0 -37
  117. package/deploy/interface.d.ts.map +0 -1
  118. package/deploy/interface.js +0 -176
  119. package/deploy/start.d.ts.map +0 -1
  120. /package/deploy/{start.d.ts → firebase/start.d.ts} +0 -0
@@ -0,0 +1,326 @@
1
+
2
+ import { html, css, LitElement, CSSResultArray } from 'lit';
3
+ import { property, state } from 'lit/decorators.js';
4
+ import { store, AppState } from '../../../store';
5
+ import { connect } from 'pwa-helpers';
6
+ import { auth, storage, user } from '../../../firebase/start';
7
+ import { updateProfile } from 'firebase/auth';
8
+ import { accImage } from '../../../redux/backend';
9
+ import { ref, updateMetadata, getDownloadURL, uploadBytesResumable } from "@firebase/storage";
10
+ import { labelStyle } from '../../../css/form/label';
11
+
12
+ export class ContactPhoto extends connect(store)(LitElement) {
13
+
14
+ /** @attr photo */
15
+ @property() public photo : string | void | any = '';
16
+
17
+ @state() private user : string | void = '';
18
+ @state() private login : boolean = false;
19
+ //@state() private uploadProgress = 0;
20
+ //@state() private uploadComplete = false;
21
+
22
+ @state() private progress: number = 0;
23
+ // @state() private downloadURL: string = '';
24
+ @state() private error: string = '';
25
+ @state() private status: string = '';
26
+
27
+
28
+ constructor() {
29
+ super();
30
+ this.progress = 0;
31
+ // this.downloadURL = '';
32
+ this.error = '';
33
+ this.status = '';
34
+ }
35
+
36
+ stateChanged(state: AppState) {
37
+ this.login = state.frontend!.login;
38
+ this.user = state.backend!.userId;
39
+ this.photo = state.backend!.photoURL;
40
+ }
41
+
42
+ // protected firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
43
+
44
+ // }
45
+
46
+ static get styles():CSSResultArray {
47
+ return[
48
+ labelStyle,
49
+ css`
50
+
51
+ :host {
52
+ box-sizing: border-box;
53
+ -webkit-box-sizing: border-box;
54
+ display: grid;
55
+ grid-template-columns: 1fr;
56
+ grid-gap: 4px;
57
+ width: 100%;
58
+ }
59
+
60
+ input[type=file] {
61
+ border-radius: 50%;
62
+ overflow: hidden;
63
+ margin: auto;
64
+ border: 2px solid #303030;
65
+ box-shadow: 1px 1px 2px black, 0 0 25px grey, 0 0 5px #fff;
66
+ }
67
+
68
+ `
69
+ ]
70
+ }
71
+
72
+ protected render() {
73
+ return html`
74
+ <label
75
+ for="pwa-uploader"
76
+ style="
77
+ grid-template-columns: auto 1fr;
78
+ grid-gap:16px;
79
+ padding: 0 16px;
80
+ ">Upload:
81
+ <progress
82
+ id ="pwa-uploader"
83
+ class ="uploader"
84
+ value ="0"
85
+ max ="100"
86
+ style="
87
+ height: 24px;
88
+ width: 100%;
89
+ margin: auto;
90
+ "></label>
91
+
92
+
93
+
94
+ <!-- Input - Upload Image -->
95
+ <input
96
+ id ="photoURL"
97
+ type ="file"
98
+ name ="photoURL"
99
+ class ="contractorPhoto"
100
+ accept ="image/*"
101
+ @change ="${this.saveImage}"
102
+ ?disabled="${this.login === false}"
103
+ style ="
104
+ display: none;
105
+ cursor: pointer;
106
+ position: absolute;
107
+ z-index: -1;
108
+ "/></progress>
109
+
110
+ <label
111
+ style="
112
+ border: 2px dashed;
113
+ border-radius: 6px;
114
+ overflow: hidden;
115
+ padding: 0 16px 16px 16px;
116
+ "
117
+ for ="photoURL">Photo:
118
+
119
+ <!-- Output - Retrieved Image -->
120
+ <canvas
121
+ style="
122
+ margin: auto;
123
+ height: 200px;
124
+ width: 100%;
125
+ background-image: url(${this.photo});
126
+ background-size: contain;
127
+ background-repeat: no-repeat;
128
+ background-position: center;
129
+ cursor: pointer;
130
+ overflow: hidden;
131
+ box-sizing: border-box;
132
+ ">
133
+ </canvas>
134
+
135
+ </label>
136
+
137
+ <p style="text-align:center;">${this.status}${this.error}</p>
138
+ `;
139
+ }
140
+
141
+
142
+
143
+
144
+
145
+ /*
146
+
147
+ private appendToFileLocation(filePath: string, appendString: string): string {
148
+
149
+ const lastDotIndex = filePath.lastIndexOf('.'); // Find the last dot to get the file extension
150
+
151
+ if (lastDotIndex <= 0) return filePath; // If there's no dot or it's at the beginning, don't alter the filePath
152
+
153
+ const basePath = filePath.substring(0, lastDotIndex); // Slice the filePath into the base path and extension
154
+ const extension = filePath.substring(lastDotIndex); // Includes the dot
155
+
156
+ // console.log('path: ', basePath, appendString, extension);
157
+
158
+ return `${basePath}${appendString}${extension}`; // Append the string and add the extension back
159
+ }
160
+
161
+ */
162
+
163
+
164
+ // Save Image to Storage and Database - Update Profile Photo URL in Database and State
165
+ private async saveImage() {
166
+
167
+ // Select Progress Bar
168
+ const uploader: HTMLProgressElement = this.shadowRoot!.querySelector('.uploader')!;
169
+
170
+
171
+ if(auth.currentUser){
172
+
173
+ this.error = '';
174
+ this.status = 'Uploading...';
175
+
176
+
177
+ // Select: File
178
+ const file : any = this.shadowRoot!.querySelector('#photoURL');
179
+
180
+ // If File Empty
181
+ if (!file) {
182
+ console.error('No file selected');
183
+ return;
184
+ }
185
+
186
+ // Test Storage Reference location.fullPath location.name location.bucket
187
+ const location = ref(storage,
188
+ "/" +
189
+ "pwa-auth" +
190
+ "/" +
191
+ this.user +
192
+ "/" +
193
+ file.files[0].name );
194
+
195
+ // const uploadTask = uploadBytesResumable(location, file);
196
+
197
+ // Create metadata from file information
198
+ const newMetadata = {
199
+ cacheControl: 'public,max-age=300',
200
+ contentType: file.files[0].type // 'image/jpeg'
201
+ };
202
+
203
+
204
+
205
+
206
+
207
+ // Upload - Blob or File API
208
+ const uploadTask = uploadBytesResumable (location, file.files[0], newMetadata);// .then((snapshot:any) => {
209
+
210
+
211
+
212
+
213
+
214
+ // Monitor upload progress
215
+ uploadTask.on(
216
+ 'state_changed',
217
+ (snapshot) => {
218
+ // Calculate progress percentage safely
219
+ this.progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
220
+ this.status = `Upload is ${Math.round(this.progress)}% done`;
221
+ switch (snapshot.state) {
222
+ case 'paused':
223
+ this.status = 'Upload is paused';
224
+ break;
225
+ case 'running':
226
+ this.status = `Upload is running (${Math.round(this.progress)}%)`;
227
+ break;
228
+ }
229
+
230
+ let progress = 0;
231
+ if (snapshot.totalBytes > 0) {
232
+ progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
233
+ }
234
+ // Ensure progress is finite before setting
235
+ if (isFinite(progress)) {
236
+ uploader.value = progress;
237
+ uploader.textContent = `${Math.round(progress)}%`;
238
+ } else {
239
+ uploader.value = 0;
240
+ uploader.textContent = '0%';
241
+ }
242
+ },
243
+ (error) => {
244
+ // Handle errors
245
+ this.error = `Upload failed: ${error.message}`;
246
+ this.status = '';
247
+
248
+ console.error('Upload failed:', error);
249
+ uploader.value = 0;
250
+ uploader.textContent = 'Error';
251
+ // uploadButton.disabled = false;
252
+ },
253
+ async () => {
254
+ // Upload completed successfully
255
+
256
+
257
+
258
+ // Get URL
259
+ await getDownloadURL(uploadTask.snapshot.ref)
260
+ .then( (url:any) => {
261
+
262
+ // Update metadata properties
263
+ updateMetadata(location, newMetadata)
264
+ .then((/*metadata:any*/) => { /* console.log("metadata: ", metadata); */ }).catch((error:any) => { console.log("error: ", error); });
265
+
266
+ // To Do: Save Minified Photo - Service
267
+ // const modifiedFilePath = this.appendToFileLocation(url, '_400x400');
268
+ // console.log('modifiedFilePath', modifiedFilePath);
269
+
270
+ if (user) {
271
+
272
+ updateProfile(user, { photoURL: url })
273
+ .then(() => {
274
+ // console.log('Profile picture updated successfully');
275
+ uploader.value = 100;
276
+ uploader.textContent = 'Complete';
277
+ });
278
+
279
+ this.status = 'User profile updated successfully!';
280
+
281
+ // const resizedLocation = ref(storage, 'images/article/' + file.name + '_400x400' ); // Path where the image will be stored in Firebase Storage
282
+
283
+ // Save URL
284
+ this.dispatchPhoto(url);
285
+
286
+ } // End If Statement
287
+
288
+ }).catch( () => {} );
289
+
290
+ // }).catch( () => {} );
291
+
292
+ });
293
+
294
+
295
+
296
+ } // End - if (auth.currentUser) {}
297
+
298
+
299
+
300
+ }
301
+
302
+ // UPDATE - PROFILE + Firestore Database + STATE - SAVE FILE LOCATION
303
+ private dispatchPhoto = async (url:string) => {
304
+
305
+ if ( auth.currentUser ) {
306
+
307
+ // Update Profile Photo URL in Database - Firestore
308
+ await updateProfile( auth.currentUser, { photoURL: url }).catch((error:Error) => { console.log(error); });
309
+
310
+ // Update Profile Photo URL in State - Redux
311
+ store.dispatch( accImage(url) );
312
+
313
+ }
314
+
315
+ }
316
+
317
+ }
318
+
319
+ customElements.define('contact-photo', ContactPhoto);
320
+
321
+ declare global {
322
+ interface HTMLElementTagNameMap {
323
+ 'contact-photo': ContactPhoto;
324
+ }
325
+ }
326
+
@@ -0,0 +1,202 @@
1
+ import { css, html, LitElement } from 'lit';
2
+ import { state, customElement } from 'lit/decorators.js';
3
+ import { connect } from 'pwa-helpers/connect-mixin.js';
4
+ import { store, AppState } from '../../store';
5
+ import { navigateAuth } from '../../redux/frontend';
6
+ import { navigation } from './css/navigation';
7
+ import './input/uploader';
8
+ import './input/name';
9
+ import './input/email';
10
+ import './input/password';
11
+ import './input/delete';
12
+ import { listStyle } from '../../css/form/list';
13
+
14
+ @customElement('user-settings')
15
+ export class UserSettings extends connect(store)(LitElement) {
16
+
17
+ @state() private profileTopic = '';
18
+ @state() private name = '';
19
+
20
+ constructor() { super(); }
21
+
22
+ protected firstUpdated() {
23
+
24
+ /* Form Default */
25
+ const forms = this.querySelectorAll('form')!
26
+ forms.forEach( item => {
27
+ item.preventDefault();
28
+ });
29
+
30
+ /* 1 */
31
+ this.shadowRoot!.querySelector('button[value=profile]')!.addEventListener('click', () => {
32
+ store.dispatch(navigateAuth('profile'));
33
+ } );
34
+
35
+ /* 2 */
36
+ this.shadowRoot!.querySelector('button[value=verification]')!.addEventListener('click', () => {
37
+ store.dispatch(navigateAuth('verification'));
38
+ } );
39
+
40
+ /* 3 */
41
+ this.shadowRoot!.querySelector('button[value=password]')!.addEventListener('click', () => {
42
+ store.dispatch(navigateAuth('password'));
43
+ } );
44
+
45
+ /* 4 */
46
+ this.shadowRoot!.querySelector('button[value=delete]')!.addEventListener('click', () => {
47
+ store.dispatch(navigateAuth('delete'));
48
+ } );
49
+
50
+ }
51
+
52
+ stateChanged(state: AppState) {
53
+ this.profileTopic = state.frontend!.settings; // Page String
54
+ this.name = state.backend!.name; // Username
55
+ }
56
+
57
+ static get styles() { return [
58
+ navigation,
59
+ listStyle,
60
+ css`
61
+
62
+ /* Button Padding for Border Outline */
63
+ :host {
64
+ display: grid;
65
+ background-color: var(--pwa_settings_background);
66
+ }
67
+
68
+ /* Page Form */
69
+ form {
70
+ box-sizing: border-box;
71
+ display: grid;
72
+ border: 0;
73
+ }
74
+
75
+ /* Page Title */
76
+ .pageTitle { margin: 0; }
77
+
78
+ h2 {
79
+ color: var(--pwa_section_header);
80
+ text-align: center;
81
+ text-shadow: 1px 1px 2px black, 0 0 15px grey, 0 0 5px #fff;
82
+
83
+ border-top: 2px solid var(--pwa_divider);
84
+ border-bottom: 2px solid var(--pwa_divider);
85
+
86
+ margin: 0;
87
+ padding: 8px 0;
88
+ }
89
+
90
+ /* up to 576 pixels */
91
+ @media only screen and (max-width: 576px) {
92
+ h2 {
93
+ font-size: medium;
94
+ }
95
+ }
96
+
97
+ `
98
+ ]; }
99
+
100
+ protected render() {
101
+ return html`
102
+
103
+ <!-- Page Menu -->
104
+ <nav>
105
+
106
+ <ul>
107
+
108
+ <li>
109
+ <button
110
+ value="profile"
111
+ ?on="${ this.profileTopic === 'profile'}">Icon
112
+ </button>
113
+ </li>
114
+
115
+ <li>
116
+ <button
117
+ value="verification"
118
+ ?on="${ this.profileTopic === 'verification'}">Profile
119
+ </button>
120
+ </li>
121
+
122
+ <li>
123
+ <button
124
+ value="password"
125
+ ?on="${ this.profileTopic === 'password'}">Password
126
+ </button>
127
+ </li>
128
+
129
+ <li>
130
+ <button
131
+ value="delete"
132
+ ?on="${ this.profileTopic === 'delete'}">Delete
133
+ </button>
134
+ </li>
135
+
136
+ </ul>
137
+
138
+ </nav>
139
+
140
+ <!-- Page 1: Profile -->
141
+ <section ?on="${ this.profileTopic === 'profile' }">
142
+
143
+ <!-- Display Username -->
144
+ <h2>${this.name}</h2>
145
+
146
+ <!-- Custom Image Element - Display / Upload -->
147
+ <contact-photo></contact-photo>
148
+
149
+ </section>
150
+
151
+ <!-- Page 2: Verification -->
152
+ <section ?on="${ this.profileTopic === 'verification' }">
153
+
154
+ <!-- Page Title -->
155
+ <h2>Contact Information</h2>
156
+
157
+ <!-- Custom - Username -->
158
+ <input-name></input-name>
159
+
160
+ <!-- Custom - Email -->
161
+ <contact-email></contact-email>
162
+
163
+ <!-- Indicator - Verified -->
164
+ <div class="verified"></div>
165
+
166
+ </section>
167
+
168
+ <!-- Page 3: Password -->
169
+ <section ?on="${ this.profileTopic === 'password' }">
170
+
171
+ <!-- Page Title -->
172
+ <h2>Password</h2>
173
+
174
+ <!-- Custom - Password -->
175
+ <input-password></input-password>
176
+
177
+ </section>
178
+
179
+ <!-- Page 4: Delete -->
180
+ <section ?on="${ this.profileTopic === 'delete' }">
181
+
182
+ <!-- Page Title -->
183
+ <h2>Delete Account</h2>
184
+
185
+ <!-- Custom - Delete -->
186
+ <delete-user></delete-user>
187
+
188
+ </section>
189
+
190
+ `
191
+ }
192
+
193
+ }
194
+
195
+ declare global {
196
+ interface HTMLElementTagNameMap {
197
+ 'user-settings': UserSettings;
198
+ }
199
+ }
200
+
201
+
202
+