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.
Files changed (50) hide show
  1. package/CHANGELOG.md +76 -4
  2. package/README.md +113 -83
  3. package/demo/index.html +93 -101
  4. package/demo/styles.css +52 -0
  5. package/images/empty.jpg +0 -0
  6. package/images/favicon.ico +0 -0
  7. package/images/manifest/logo-144.png +0 -0
  8. package/images/manifest/logo-192.png +0 -0
  9. package/images/manifest/logo-48.png +0 -0
  10. package/images/manifest/logo-512.png +0 -0
  11. package/images/manifest/logo-72.png +0 -0
  12. package/images/manifest/logo-96.png +0 -0
  13. package/images/manifest/maskable_icon_x128.png +0 -0
  14. package/images/manifest/maskable_icon_x192.png +0 -0
  15. package/images/manifest/maskable_icon_x384.png +0 -0
  16. package/images/manifest/maskable_icon_x48.png +0 -0
  17. package/images/manifest/maskable_icon_x512.png +0 -0
  18. package/images/manifest/maskable_icon_x72.png +0 -0
  19. package/images/manifest/maskable_icon_x96.png +0 -0
  20. package/images/npm.svg +85 -85
  21. package/license +21 -21
  22. package/manifest.json +47 -44
  23. package/npm/pwa-auth.js +3163 -0
  24. package/npm/pwa-auth.js.map +1 -0
  25. package/package.json +50 -38
  26. package/deploy/store.js +0 -18
  27. package/deploy/styles-drawer.js +0 -139
  28. package/deploy/styles-settings.js +0 -57
  29. package/deploy/styles.js +0 -88
  30. package/deploy/user-action.js +0 -69
  31. package/deploy/user-drawer.js +0 -163
  32. package/deploy/user-functions.js +0 -175
  33. package/deploy/user-icon.js +0 -107
  34. package/deploy/user-reducer.js +0 -41
  35. package/deploy/user-settings.js +0 -418
  36. package/polymer.json +0 -24
  37. package/pwa-auth.js +0 -16
  38. package/robots.txt +0 -2
  39. package/src/store.ts +0 -52
  40. package/src/styles-drawer.ts +0 -143
  41. package/src/styles-settings.ts +0 -61
  42. package/src/styles.ts +0 -95
  43. package/src/user-action.ts +0 -91
  44. package/src/user-drawer.ts +0 -162
  45. package/src/user-functions.ts +0 -173
  46. package/src/user-icon.ts +0 -106
  47. package/src/user-reducer.ts +0 -91
  48. package/src/user-settings.ts +0 -402
  49. package/tsconfig.json +0 -19
  50. package/webpack.config.js +0 -72
@@ -1,61 +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
-
14
- import { css } from 'lit-element';
15
-
16
- export const Settings = css`
17
-
18
- form { box-sizing: border-box; }
19
- .pageTitle { margin: 0; }
20
-
21
- form {
22
- max-width: 600px;
23
- margin: auto;
24
- border: 0;
25
- }
26
-
27
- .setMenu {
28
- display: grid;
29
- grid-template-columns: 1fr 1fr 1fr 1fr;
30
- grid-gap: 8px;
31
- margin: 0px;
32
- padding: 0px;
33
- }
34
-
35
- .topButton {
36
- color: grey;
37
- border: 0;
38
- width: 100%;
39
- height: 36px;
40
- margin: auto;
41
- padding: 0px;
42
- font-weight: 800;
43
- font-size: .8em;
44
- border-radius: 5px;
45
- background-color: transparent;
46
- }
47
-
48
- .topButton[on] {
49
- /* background-color: rgba(0,0,0, .1); */
50
- color: var(--app-black-color);
51
- }
52
-
53
- .topButton:hover {
54
- cursor: pointer;
55
- }
56
-
57
- .topButton > p {
58
- margin: 0px;
59
- }
60
-
61
- `;
package/src/styles.ts DELETED
@@ -1,95 +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
-
14
- import { html, css } from 'lit-element';
15
-
16
- export const userStyles = css`
17
-
18
- .spec[on] { display: block; }
19
- .spec { display: none; }
20
-
21
- .x-font {
22
- font-family: Roboto, Arial, sans-serif; /* 'Montserrat' */
23
- line-height: 1.1;
24
- letter-spacing: .007em;
25
- font-size: 14px;
26
- font-weight: 500;
27
- text-align: center;
28
- text-decoration-style: solid;
29
- text-transform: uppercase;
30
- }
31
-
32
- ul {
33
- list-style-type: none;
34
- padding: 0;
35
- margin: 0;
36
- }
37
-
38
- input[type=submit]:hover { background-color: #45a049; }
39
- input[type=submit] {
40
- box-sizing: border-box;
41
- width: 100%;
42
- background-color: #4CAF50;
43
- color: white;
44
- padding: 14px 20px;
45
- margin: 8px 0;
46
- border: none;
47
- border-radius: 4px;
48
- cursor: pointer;
49
- }
50
-
51
- input.invalid { background-color: #ffdddd; }
52
- input[type=text],
53
- input[type=email],
54
- input[type=password], select {
55
- box-sizing: border-box;
56
- width: 100%;
57
- padding: 8px 16px;
58
- border-radius: 4px;
59
- background-color: rgba(228, 241, 254, 1);
60
- border: 1px #ccc solid;
61
- border-bottom: 2px var(--app-black-color) solid;
62
- border-radius: 5px;
63
- text-align: center;
64
- }
65
-
66
- .action-button:focus, .topButton:focus {outline:0;}
67
- .action-button {
68
- display: inline-block;
69
- box-sizing: border-box;
70
- white-space: nowrap;
71
- margin: 10px 0 10px 0;
72
- font-weight: 400;
73
- text-align: center;
74
- vertical-align: middle;
75
- touch-action: manipulation;
76
- -webkit-appearance: button;
77
- cursor: pointer;
78
- font-size: 16px;
79
- height: 38px;
80
- line-height: 16px;
81
- width: 100%;
82
- padding: 10px 16px;
83
- border-radius: 6px;
84
- color: #fff;
85
- background-color: #6cc04a;
86
- border-color: #60b23e;
87
- box-shadow: 1px 1px 1px grey;
88
- }
89
-
90
- `;
91
-
92
- export const settings = html`<svg viewBox="0 0 24 24"><path d="M19.43 12.98c.04-.32.07-.64.07-.98s-.03-.66-.07-.98l2.11-1.65c.19-.15.24-.42.12-.64l-2-3.46c-.12-.22-.39-.3-.61-.22l-2.49 1c-.52-.4-1.08-.73-1.69-.98l-.38-2.65C14.46 2.18 14.25 2 14 2h-4c-.25 0-.46.18-.49.42l-.38 2.65c-.61.25-1.17.59-1.69.98l-2.49-1c-.23-.09-.49 0-.61.22l-2 3.46c-.13.22-.07.49.12.64l2.11 1.65c-.04.32-.07.65-.07.98s.03.66.07.98l-2.11 1.65c-.19.15-.24.42-.12.64l2 3.46c.12.22.39.3.61.22l2.49-1c.52.4 1.08.73 1.69.98l.38 2.65c.03.24.24.42.49.42h4c.25 0 .46-.18.49-.42l.38-2.65c.61-.25 1.17-.59 1.69-.98l2.49 1c.23.09.49 0 .61-.22l2-3.46c.12-.22.07-.49-.12-.64l-2.11-1.65zM12 15.5c-1.93 0-3.5-1.57-3.5-3.5s1.57-3.5 3.5-3.5 3.5 1.57 3.5 3.5-1.57 3.5-3.5 3.5z"></path></svg>`;
93
- export const close = html`<svg viewBox="0 0 24 24"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"></path></svg>`;
94
-
95
-
@@ -1,91 +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 { Action, ActionCreator } from 'redux';
13
- import { ThunkAction } from 'redux-thunk';
14
- import { RootState } from './store.js';
15
-
16
- export const LOGGED_IN = 'LOGGED_IN';
17
- export const SETTINGS_PAGE = 'SETTINGS_PAGE';
18
-
19
- export const PROFILE_TYPE = 'PROFILE_TYPE';
20
- export const SIGN_IN = 'SIGN_IN';
21
-
22
- export const SET_USER = 'SET_USER';
23
- export const SET_IMAGE = 'SET_IMAGE';
24
- export const SET_NAME = 'SET_NAME';
25
-
26
- export const OPEN_SIGN = 'OPEN_SIGN';
27
- export const CLOSE_SIGN = 'CLOSE_SIGN';
28
-
29
- export const SIGN_UP_OPEN = "SIGN_UP_OPEN";
30
- export const SIGN_UP_CLOSE = "SIGN_UP_CLOSE";
31
-
32
- // export interface updateLoginX extends Action<'LOGGED_IN'> { logged: boolean };
33
- export interface navigateX extends Action<'SETTINGS_PAGE'> { option: string };
34
- export interface setImageX extends Action<'SET_IMAGE'> { image: string };
35
- export interface setNameX extends Action<'SET_NAME'> { name: string };
36
-
37
- export interface setAuthX extends Action<'LOGGED_IN'> { currentUser: boolean };
38
- export interface setUserX extends Action<'SET_USER'> { user: string };
39
- export interface profileX extends Action<'PROFILE_TYPE'> { profileType: string };
40
-
41
- export interface openSignX extends Action<'OPEN_SIGN'> { };
42
- export interface closeSignX extends Action<'CLOSE_SIGN'> { };
43
-
44
- export interface signUpOpen extends Action<'SIGN_UP_OPEN'> { };
45
- export interface signUpClose extends Action<'SIGN_UP_CLOSE'> { };
46
-
47
- export type AppAction = closeSignX | openSignX | signUpOpen | signUpClose | navigateX | setImageX | setNameX | setAuthX | setUserX | profileX;
48
-
49
- // export type AppAction = closeSignX | openSignX | signUpOpen | signUpClose | setImageX | setNameX ;
50
-
51
- type ThunkResult = ThunkAction<void, RootState, undefined, AppAction>;
52
-
53
- // NAVIGATION
54
- export const navigate: ActionCreator<navigateX> = (option: string) => {
55
- switch(option) {
56
-
57
- case 'profile':
58
- break;
59
- case 'email':
60
- break;
61
- case 'password':
62
- break;
63
- case 'delete':
64
- break;
65
-
66
- default: option = 'profile';
67
-
68
- }
69
- return { type: SETTINGS_PAGE, option }
70
- }
71
-
72
- export const openSign: ActionCreator<ThunkResult> = ( snackState: boolean ) => (dispatch, getState) => {
73
- if ( getState().user!.snackState === true) { dispatch({ type: CLOSE_SIGN, snackState }); }
74
- else { dispatch({ type: OPEN_SIGN, snackState }); }
75
- }
76
- export const signUp: ActionCreator<ThunkResult> = ( register: boolean ) => (dispatch, getState) => {
77
- if ( getState().user!.register === false) { dispatch({ type: SIGN_UP_OPEN, register }); }
78
- else { dispatch({ type: SIGN_UP_CLOSE, register }); }
79
- }
80
-
81
- // export const updateLogin: ActionCreator<updateLoginX> = ( logged: boolean ) => { return { type: LOGGED_IN, logged }; };
82
- export const setAuth: ActionCreator<setAuthX> = ( currentUser: boolean ) => { return { type: LOGGED_IN, currentUser }; };
83
- export const setUser: ActionCreator<setUserX> = ( user: string ) => { return { type: SET_USER, user }; };
84
-
85
- export const setImage: ActionCreator<setImageX> = ( image: string ) => { return { type: SET_IMAGE, image }; };
86
- export const setName: ActionCreator<setNameX> = ( name: string ) => { return { type: SET_NAME, name }; };
87
- export const closeSign: ActionCreator<closeSignX> = ( closeLogIN: boolean ) => { return { type: CLOSE_SIGN, closeLogIN } };
88
-
89
- // export const profile: ActionCreator<profileX> = ( profileType: string ) => { return { type: PROFILE_TYPE, profileType } };
90
- // export const signUp = (register) => { return { type: IN_UP, register }; }
91
-
@@ -1,162 +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 _signIn() {
57
- const a = this.shadowRoot.getElementById('logs');
58
- a.addEventListener('click', e => { e.preventDefault(); });
59
- // Prevent Form's Page Refresh
60
- const email = this.shadowRoot.getElementById('txtEmail').value;
61
- const password = this.shadowRoot.getElementById('txtPassword').value;
62
- // @ts-ignore
63
- firebase.auth().signInWithEmailAndPassword(email, password).catch( (error) => {
64
- const errorCode = error.code;
65
- const errorMessage = error.message;
66
- });
67
- }
68
-
69
- private _signUp() {
70
- const email = this.shadowRoot.getElementById('newtEmail').value;
71
- const pass = this.shadowRoot.getElementById('newPassword').value;
72
- if (email.length < 4) {
73
- alert('Please enter an email address.');
74
- return;
75
- }
76
- if (pass.length < 4) {
77
- alert('Please enter a password.');
78
- return;
79
- }
80
- // @ts-ignore
81
- firebase.auth().createUserWithEmailAndPassword(email, pass).catch( (error) => {
82
- const errorCode = error.code;
83
- const errorMessage = error.message;
84
- // [START_EXCLUDE]
85
- if (errorCode == 'auth/weak-password') {
86
- alert('The password is too weak.');
87
- } else {
88
- alert(errorMessage);
89
- }
90
- console.log(error);
91
-
92
- });
93
- }
94
-
95
- static get styles() {
96
- return [
97
- userStyles,
98
- User,
99
- css`
100
- :host {
101
-
102
- }
103
- `
104
- ]}
105
-
106
- protected render() {
107
- return html`
108
-
109
- <!-- Login Wrapper -->
110
- <div class="visibility userDrawer" ?on="${ this._subscribe === true }">
111
-
112
- <div class="exit">
113
- <div></div>
114
- <h3 id="or">${this._log ? html`ACCOUNT` : html`SUBSCRIBE` }</h3>
115
- <button id="close" class="sign-right">${close}</button>
116
- </div>
117
-
118
- <div class="spec" ?on="${ this._log === false }">
119
-
120
- <p><button id="new">create a new account</button></p>
121
-
122
- <p><button id="googleSignIn" class="google">
123
- <span class="icon"></span>
124
- <span class="buttonText">Sign in with Google</span>
125
- </button></p>
126
-
127
- <form id="logs" autocomplete="on" class="spec" ?on="${ this._sign === true }">
128
- <ul>
129
- <li class="inpat">
130
- <label><input id="txtEmail" type="email" >Email</label>
131
- <label><input id="txtPassword" type="Password" >Password</label>
132
- </li>
133
- <li><button id="log" class="action-button">Sign in</button></li>
134
- </ul>
135
- </form>
136
-
137
- <!-- Sign UP -->
138
- <form id="signup" autocomplete="on" class="spec" ?on="${ this._sign === false }">
139
- <ul>
140
- <li class="inpat">
141
- <label><input id="newEmail" type="email" >Email</label>
142
- <label><input id="newPassword" type="Password" >Password</label>
143
- <label><input id="verifyEmail" type="email" >Verify Email</label>
144
- <label><input id="veriftPassword" type="Password" >Verify Password</label>
145
- </li>
146
- <li><button id="newUser" class="action-button">Sign up</button></li>
147
- </ul>
148
- </form>
149
-
150
- </div>
151
-
152
- <!-- Logged IN -->
153
- <div class="spec setLog" ?on="${ this._log === true }">
154
- <slot></slot>
155
- <p><a href="/settings">Settings</a></p>
156
- <p><a id="leave" aria-label="log out">log out</a></p>
157
- </div>
158
-
159
- </div>
160
- `;
161
- }
162
- }
@@ -1,173 +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
-
14
- import { store } from './store';
15
- import { setUser, setAuth } from './user-action';
16
-
17
-
18
-
19
- // export const runList = () => { firebase.auth().onAuthStateChanged( (firebaseUser) => { if (firebaseUser) { store.dispatch(setList(firebaseUser)); } else { store.dispatch(setList(firebaseUser)); } }); };
20
- export const runFirebase = () => { firebase.auth().onAuthStateChanged( (firebaseUser: boolean) => {
21
- if (firebaseUser) { store.dispatch(setAuth(true)); store.dispatch(setUser(firebaseUser)); }
22
- else { store.dispatch(setAuth(false)); store.dispatch(setUser(firebaseUser)); }
23
- }); };
24
-
25
- export const authChange = () => { return firebase.auth().onAuthStateChanged( (firebaseUser: boolean) => { if(firebaseUser) {store.dispatch( setAuth(true) )} else{store.dispatch( setAuth(false) )} });}
26
-
27
- export const firebaseUser = () => { return firebase.auth().currentUser || "demo"; };
28
- export const firebaseID = () => { return firebase.auth().currentUser.uid || "demo" ; };
29
-
30
- export const logOut = () => { return firebase.auth().signOut(); }; /* .then( () => { } ).catch( () => { } ) */
31
- export const isUser = () => { return !!firebase.auth().currentUser; };
32
-
33
- export const profileURL = () => { return firebase.auth().currentUser.photoURL || '/images/manifest/icon-48x48.png'; };
34
- export const userName = () => { return firebase.auth().currentUser.displayName; };
35
- export const userEmail = () => { return firebase.auth().currentUser.email; };
36
-
37
- export const deleteUser = () => { return firebase.auth().currentUser.delete() }; /* .then( () => { }).catch( () => { }) */
38
- export const deleteDoc = (collect:string, item:string) => { return firestore.collection(collect).doc(item).delete() };
39
-
40
- // export const storageRef = () => { return firebase.storage.ref(); }
41
-
42
- export const saveMessage = (messageText:string) => {
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
- };
52
- export const loadMessages = () => {
53
- // Create the query to load the last 12 messages and listen for new ones.
54
- const query = firebase.firestore().collection('messages').orderBy('timestamp', 'desc').limit(12);
55
- // Start listening to the query.
56
- query.onSnapshot( (snapshot) => {
57
- snapshot.docChanges().forEach( (change) => {
58
- if (change.type === 'removed') {
59
- // deleteMessage(change.doc.id);
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:string) => {
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:string) => {
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
- } else {
98
- // Need to request permissions to show notifications.
99
- requestNotificationsPermissions();
100
- }
101
- }).catch( (error) => { console.error('Unable to get messaging token.', error); });
102
- };
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
- } else {
122
- alert(errorMessage);
123
- }
124
- console.log(error);
125
- });
126
-
127
- }
128
-
129
- export const anon = () => {
130
- if (firebase.auth().currentUser) {
131
- // [START signout]
132
- firebase.auth().signOut();
133
- // [END signout]
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
- } else { console.error(error); }
144
- // [END_EXCLUDE]
145
- });
146
- // [END authanon]
147
- }
148
- };
149
-
150
- export const google = () => {
151
- const provider = new firebase.auth.GoogleAuthProvider();
152
- provider.addScope('profile');
153
- provider.addScope('email');
154
- firebase.auth().signInWithRedirect(provider);
155
- firebase.auth().getRedirectResult().then( (result) => {
156
- if (result.credential) {
157
- // This gives you a Google Access Token. You can use it to access the Google API.
158
- const token = result.credential.accessToken; console.log("Google Token");
159
- }
160
- // The signed-in user info.
161
- const firebaseUser = result.firebaseUser;
162
- }).catch( (error) => {
163
- // Handle Errors here.
164
- const errorCode = error.code;
165
- const errorMessage = error.message;
166
- // The email of the user's account used.
167
- const email = error.email;
168
- // The firebase.auth.AuthCredential type that was used.
169
- const credential = error.credential;
170
- });
171
- };
172
-
173
- // window.onerror = function(message, file, line, col, error){ console.log(arguments); }
package/src/user-icon.ts DELETED
@@ -1,106 +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
-
14
- import { html, LitElement, css, customElement, property } from 'lit-element';
15
- import { connect } from 'pwa-helpers/connect-mixin.js';
16
- import { store, RootState } from './store';
17
- import { userStyles } from './styles';
18
- import { openSign, setImage } from './user-action';
19
- import { profileURL } from './user-functions';
20
-
21
- 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>`;
22
-
23
- @customElement('user-icon')
24
- export class UserIcon extends connect(store)(LitElement) {
25
-
26
- @property({type: Boolean})
27
- private _user = false;
28
-
29
- @property({type: String})
30
- private _photoURL = '';
31
-
32
-
33
- constructor() {
34
- super();
35
- }
36
-
37
- protected firstUpdated() {
38
- this.shadowRoot.getElementById('subscribe').addEventListener('click', () => { store.dispatch(openSign()) } );
39
-
40
- // @ts-ignore
41
- firebase.auth().onAuthStateChanged( (firebaseUser) => {
42
- if (firebaseUser) { /* INCLUDE */ this._photoURL = profileURL(); }
43
- else { /* EXCLUDE */ }
44
- store.dispatch( setImage( this._photoURL ) );
45
- });
46
- }
47
-
48
- stateChanged(state: RootState) {
49
- this._user = state.user!.currentUser;
50
- this._photoURL = state.user!.photoURL;
51
- }
52
-
53
-
54
- static get styles() {
55
- return [
56
- userStyles,
57
- css`
58
- :host { margin: auto; display: block; }
59
-
60
- #subscribe:hover { background-color: lightgrey; }
61
- #subscribe {
62
- display: block;
63
- margin: auto;
64
- padding: 0;
65
- background: #fff;
66
- border-radius: 50%;
67
- clip-path: circle(50%);
68
- overflow: hidden;
69
- width: 36px;
70
- height: 36px;
71
- }
72
- userImage {object-fit: cover;}
73
- .iconArea {
74
- border-radius: 50%;
75
- overflow: hidden;
76
- width: 32px;
77
- height: 32px;
78
- margin: auto;
79
- }
80
- svg{ margin:auto;}
81
- `
82
- ]}
83
-
84
- protected render() {
85
- return html`
86
-
87
- <button id="subscribe" aria-label="login">
88
- ${this._user
89
- ? html`
90
- <div class="iconArea">
91
- <input
92
- type="image"
93
- class="userImage"
94
- id="image"
95
- alt="Login"
96
- height="32px"
97
- width="32px"
98
- src="${this._photoURL}">
99
- </div>
100
- `
101
- : html`${faceIcon}` }
102
- </button>
103
-
104
- `;
105
- }
106
- }