From e5b0b18119e804a5dfcf5a24e7115565a0d98315 Mon Sep 17 00:00:00 2001 From: Thomas Seillan Date: Sun, 24 May 2020 15:31:14 +0200 Subject: [PATCH 1/3] Added draft of Firebase authClient mapping. --- packages/auth/package.json | 1 + packages/auth/src/authClient.ts | 39 +++- yarn.lock | 347 ++++++++++++++++++++++++++++++-- 3 files changed, 365 insertions(+), 22 deletions(-) diff --git a/packages/auth/package.json b/packages/auth/package.json index 9b07cd704e50..19ace1b59bc6 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -10,6 +10,7 @@ "devDependencies": { "@auth0/auth0-spa-js": "^1.7.0", "@types/react": "^16.9.34", + "firebase": "^7.14.5", "gotrue-js": "^0.9.25", "netlify-identity-widget": "1.6.0", "react": "^16.13.1" diff --git a/packages/auth/src/authClient.ts b/packages/auth/src/authClient.ts index e472615f4002..e1bb7801dff2 100644 --- a/packages/auth/src/authClient.ts +++ b/packages/auth/src/authClient.ts @@ -1,14 +1,16 @@ import type { default as GoTrue, User as GoTrueUser } from 'gotrue-js' import type { Auth0Client as Auth0 } from '@auth0/auth0-spa-js' import type NetlifyIdentityNS from 'netlify-identity-widget' +// TODO: Import missing Firebase type // TODO: Can also return an Auth0 user which doesn't have a definition. // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface Auth0User {} export type { GoTrueUser } export type NetlifyIdentity = typeof NetlifyIdentityNS +// TODO: Add missing Firebase Type export type SupportedAuthClients = Auth0 | GoTrue | NetlifyIdentity -export type SupportedAuthTypes = 'auth0' | 'gotrue' | 'netlify' +export type SupportedAuthTypes = 'auth0' | 'firebase' | 'gotrue' | 'netlify' export interface AuthClient { restoreAuthState?(): void | Promise @@ -39,11 +41,11 @@ const mapAuthClientAuth0 = (client: Auth0): AuthClientAuth0 => { if (window.location.search.includes('code=')) { const { appState } = await client.handleRedirectCallback() window.history.replaceState( - {}, - document.title, - appState && appState.targetUrl - ? appState.targetUrl - : window.location.pathname + {}, + document.title, + appState && appState.targetUrl + ? appState.targetUrl + : window.location.pathname ) } }, @@ -62,7 +64,7 @@ const mapAuthClientGoTrue = (client: GoTrue): AuthClientGoTrue => { type: 'gotrue', client, login: async ({ email, password, remember }) => - client.login(email, password, remember), + client.login(email, password, remember), logout: async () => { const user = await client.currentUser() return user?.logout() @@ -112,11 +114,28 @@ const mapAuthClientNetlify = (client: NetlifyIdentity): AuthClient => { } } +const mapAuthClientFirebase = (client: Firebase): AuthClient => { + return { + type: 'firebase', + client, + restoreAuthState: () => client.auth().getRedirectResult(), + login: async () => { + const provider = new client.auth.GoogleAuthProvider() + return client.auth().signInWithRedirect(provider) + }, + logout: () => client.auth().signOut(), + getToken: async () => client.auth().currentUser.getIdToken(), + currentUser: async () => client.auth().currentUser, + } +} + export const createAuthClient = ( - client: SupportedAuthClients, - type: SupportedAuthTypes + client: SupportedAuthClients, + type: SupportedAuthTypes ): AuthClient => { switch (type) { + case 'firebase': + return mapAuthClientFirebase(client as Firebase); case 'auth0': return mapAuthClientAuth0(client as Auth0) case 'gotrue': @@ -125,7 +144,7 @@ export const createAuthClient = ( return mapAuthClientNetlify(client as NetlifyIdentity) default: throw new Error( - `The ${type} auth client is not currently supported, please consider adding it.` + `The ${type} auth client is not currently supported, please consider adding it.` ) } } diff --git a/yarn.lock b/yarn.lock index ba3772cec119..72c91af78530 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1122,6 +1122,229 @@ unique-filename "^1.1.1" which "^1.3.1" +"@firebase/analytics-types@0.3.1": + version "0.3.1" + resolved "https://registry.yarnpkg.com/@firebase/analytics-types/-/analytics-types-0.3.1.tgz#3c5f5d71129c88295e17e914e34b391ffda1723c" + integrity sha512-63vVJ5NIBh/JF8l9LuPrQYSzFimk7zYHySQB4Dk9rVdJ8kV/vGQoVTvRu1UW05sEc2Ug5PqtEChtTHU+9hvPcA== + +"@firebase/analytics@0.3.5": + version "0.3.5" + resolved "https://registry.yarnpkg.com/@firebase/analytics/-/analytics-0.3.5.tgz#f7327637281dd7c9cd74152e2f6b8cc64c1330dc" + integrity sha512-p+h1s9A8EjGWfjAObu8ei46JoN2Ogbtl1RzqW7HjcPuclOIOmPTXKEXXCEXgO79OLxnzzezVeBtHPSx6r6gxJA== + dependencies: + "@firebase/analytics-types" "0.3.1" + "@firebase/component" "0.1.12" + "@firebase/installations" "0.4.10" + "@firebase/logger" "0.2.4" + "@firebase/util" "0.2.47" + tslib "1.11.1" + +"@firebase/app-types@0.6.1": + version "0.6.1" + resolved "https://registry.yarnpkg.com/@firebase/app-types/-/app-types-0.6.1.tgz#dcbd23030a71c0c74fc95d4a3f75ba81653850e9" + integrity sha512-L/ZnJRAq7F++utfuoTKX4CLBG5YR7tFO3PLzG1/oXXKEezJ0kRL3CMRoueBEmTCzVb/6SIs2Qlaw++uDgi5Xyg== + +"@firebase/app@0.6.4": + version "0.6.4" + resolved "https://registry.yarnpkg.com/@firebase/app/-/app-0.6.4.tgz#5b857f2ba1cc286c88a3a7e1e6a1a7cc36308bee" + integrity sha512-E1Zw6yeZYdYYFurMnklKPvE+q/xleHXs7bmcVgyhgAEg3Gv6/qXI4+4GdWh+iF7wmQ3Liesh51xqfdpvHBwAMQ== + dependencies: + "@firebase/app-types" "0.6.1" + "@firebase/component" "0.1.12" + "@firebase/logger" "0.2.4" + "@firebase/util" "0.2.47" + dom-storage "2.1.0" + tslib "1.11.1" + xmlhttprequest "1.8.0" + +"@firebase/auth-interop-types@0.1.5": + version "0.1.5" + resolved "https://registry.yarnpkg.com/@firebase/auth-interop-types/-/auth-interop-types-0.1.5.tgz#9fc9bd7c879f16b8d1bb08373a0f48c3a8b74557" + integrity sha512-88h74TMQ6wXChPA6h9Q3E1Jg6TkTHep2+k63OWg3s0ozyGVMeY+TTOti7PFPzq5RhszQPQOoCi59es4MaRvgCw== + +"@firebase/auth-types@0.10.1": + version "0.10.1" + resolved "https://registry.yarnpkg.com/@firebase/auth-types/-/auth-types-0.10.1.tgz#7815e71c9c6f072034415524b29ca8f1d1770660" + integrity sha512-/+gBHb1O9x/YlG7inXfxff/6X3BPZt4zgBv4kql6HEmdzNQCodIRlEYnI+/da+lN+dha7PjaFH7C7ewMmfV7rw== + +"@firebase/auth@0.14.6": + version "0.14.6" + resolved "https://registry.yarnpkg.com/@firebase/auth/-/auth-0.14.6.tgz#3d419d9b3553f17f94ceea1aaf2cecfdac26c778" + integrity sha512-7gaEUWhUubWBGfOXAZvpTpJqBJT9KyG83RXC6VnjSQIfNUaarHZ485WkzERil43A6KvIl+f4kHxfZShE6ZCK3A== + dependencies: + "@firebase/auth-types" "0.10.1" + +"@firebase/component@0.1.12": + version "0.1.12" + resolved "https://registry.yarnpkg.com/@firebase/component/-/component-0.1.12.tgz#deb511c92c5c6f60995207312b7ede8c7076fdb2" + integrity sha512-03w800MxR/EW1m7N0Q46WNcngwdDIHDWpFPHTdbZEI6U/HuLks5RJQlBxWqb1P73nYPkN8YP3U8gTdqrDpqY3Q== + dependencies: + "@firebase/util" "0.2.47" + tslib "1.11.1" + +"@firebase/database-types@0.5.1": + version "0.5.1" + resolved "https://registry.yarnpkg.com/@firebase/database-types/-/database-types-0.5.1.tgz#fab2f3fb48eec374a9f435ed21e138635cb9b71c" + integrity sha512-onQxom1ZBYBJ648w/VNRzUewovEDAH7lvnrrpCd69ukkyrMk6rGEO/PQ9BcNEbhlNtukpsqRS0oNOFlHs0FaSA== + dependencies: + "@firebase/app-types" "0.6.1" + +"@firebase/database@0.6.3": + version "0.6.3" + resolved "https://registry.yarnpkg.com/@firebase/database/-/database-0.6.3.tgz#d85471938a0a9d9169f1f37f8f9d2dec7ef32f8b" + integrity sha512-gHoCISHQVLoq+rGu+PorYxMkhsjhXov3ocBxz/0uVdznNhrbKkAZaEKF+dIAsUPDlwSYeZuwWuik7xcV3DtRaw== + dependencies: + "@firebase/auth-interop-types" "0.1.5" + "@firebase/component" "0.1.12" + "@firebase/database-types" "0.5.1" + "@firebase/logger" "0.2.4" + "@firebase/util" "0.2.47" + faye-websocket "0.11.3" + tslib "1.11.1" + +"@firebase/firestore-types@1.10.2": + version "1.10.2" + resolved "https://registry.yarnpkg.com/@firebase/firestore-types/-/firestore-types-1.10.2.tgz#b2286332c25dbe15becb9153ba3eedf7ab6c2a88" + integrity sha512-T1GttZezQ+gUpdDgLeLOvgS3KMeeIuodQ+JBBEd6M11zdilfTHsEHhmli15c6V3g/PfuFzyKDKExe05lPuYe4w== + +"@firebase/firestore@1.14.5": + version "1.14.5" + resolved "https://registry.yarnpkg.com/@firebase/firestore/-/firestore-1.14.5.tgz#0d7526ab8bec3e45726daad3c7c34b6aa09a71e2" + integrity sha512-BZD3RqlAEnq15i8Y53VUFsuWkbujslGaQIcuEnt6bOENzlKiLBwESmt/uGKRIsdQjc1krG2qdoPmaSMqULR0dA== + dependencies: + "@firebase/component" "0.1.12" + "@firebase/firestore-types" "1.10.2" + "@firebase/logger" "0.2.4" + "@firebase/util" "0.2.47" + "@firebase/webchannel-wrapper" "0.2.41" + "@grpc/grpc-js" "0.8.1" + "@grpc/proto-loader" "^0.5.0" + tslib "1.11.1" + +"@firebase/functions-types@0.3.17": + version "0.3.17" + resolved "https://registry.yarnpkg.com/@firebase/functions-types/-/functions-types-0.3.17.tgz#348bf5528b238eeeeeae1d52e8ca547b21d33a94" + integrity sha512-DGR4i3VI55KnYk4IxrIw7+VG7Q3gA65azHnZxo98Il8IvYLr2UTBlSh72dTLlDf25NW51HqvJgYJDKvSaAeyHQ== + +"@firebase/functions@0.4.44": + version "0.4.44" + resolved "https://registry.yarnpkg.com/@firebase/functions/-/functions-0.4.44.tgz#a0f87a16be9916f930d7e9533b4befdf7640eec2" + integrity sha512-Nbw+V/jYqfgq7wscsSDidqIzx8TrnmA2wRD1auCFNmf+gSJg8o+gNyCDdNHZI407jvrZcxp3nG1eMbqwmmnp7Q== + dependencies: + "@firebase/component" "0.1.12" + "@firebase/functions-types" "0.3.17" + "@firebase/messaging-types" "0.4.5" + isomorphic-fetch "2.2.1" + tslib "1.11.1" + +"@firebase/installations-types@0.3.4": + version "0.3.4" + resolved "https://registry.yarnpkg.com/@firebase/installations-types/-/installations-types-0.3.4.tgz#589a941d713f4f64bf9f4feb7f463505bab1afa2" + integrity sha512-RfePJFovmdIXb6rYwtngyxuEcWnOrzdZd9m7xAW0gRxDIjBT20n3BOhjpmgRWXo/DAxRmS7bRjWAyTHY9cqN7Q== + +"@firebase/installations@0.4.10": + version "0.4.10" + resolved "https://registry.yarnpkg.com/@firebase/installations/-/installations-0.4.10.tgz#3686be433a176e6e2798b674486255e6749a0b8c" + integrity sha512-Nf7VK9++0eQzjdvBkBNNaOdxPjFiKD0EllLCIQycHozF97BmuFUqb2Ik5L2JaWspWg7vxLNacLHvW48nPGx4Zw== + dependencies: + "@firebase/component" "0.1.12" + "@firebase/installations-types" "0.3.4" + "@firebase/util" "0.2.47" + idb "3.0.2" + tslib "1.11.1" + +"@firebase/logger@0.2.4": + version "0.2.4" + resolved "https://registry.yarnpkg.com/@firebase/logger/-/logger-0.2.4.tgz#276e7c482f462b5b24b188257cf162b3b2cd3ad6" + integrity sha512-akHkOU7izYB1okp/B5sxClGjjw6KvZdSHyjNM5pKd67Zg5W6PsbkI/GFNv21+y6LkUkJwDRbdeDgJoYXWT3mMA== + +"@firebase/messaging-types@0.4.5": + version "0.4.5" + resolved "https://registry.yarnpkg.com/@firebase/messaging-types/-/messaging-types-0.4.5.tgz#452572d3c5b7fa83659fdb1884450477229f5dc4" + integrity sha512-sux4fgqr/0KyIxqzHlatI04Ajs5rc3WM+WmtCpxrKP1E5Bke8xu/0M+2oy4lK/sQ7nov9z15n3iltAHCgTRU3Q== + +"@firebase/messaging@0.6.16": + version "0.6.16" + resolved "https://registry.yarnpkg.com/@firebase/messaging/-/messaging-0.6.16.tgz#72ee968c25de5d376b48556ef36b8fc69aba2316" + integrity sha512-TAPISK5y3xbxUw81HxLDP6YPsRryU6Nl8Z7AjNnem13BoN9LJ2/wCi9RDMfPnQhAn0h0N+mpxy/GB+0IlEARlg== + dependencies: + "@firebase/component" "0.1.12" + "@firebase/installations" "0.4.10" + "@firebase/messaging-types" "0.4.5" + "@firebase/util" "0.2.47" + idb "3.0.2" + tslib "1.11.1" + +"@firebase/performance-types@0.0.13": + version "0.0.13" + resolved "https://registry.yarnpkg.com/@firebase/performance-types/-/performance-types-0.0.13.tgz#58ce5453f57e34b18186f74ef11550dfc558ede6" + integrity sha512-6fZfIGjQpwo9S5OzMpPyqgYAUZcFzZxHFqOyNtorDIgNXq33nlldTL/vtaUZA8iT9TT5cJlCrF/jthKU7X21EA== + +"@firebase/performance@0.3.4": + version "0.3.4" + resolved "https://registry.yarnpkg.com/@firebase/performance/-/performance-0.3.4.tgz#d2e4f33c3ddc35dd090ba86da4dc6087b083d996" + integrity sha512-VDoqJSB+2RuXlyyP7oSvBPEmoznG84HmEtb8DQWsAHeVkf+qlec1OTZR8IjktlIv+8Pg8MMuYoB0crx5g7xU5A== + dependencies: + "@firebase/component" "0.1.12" + "@firebase/installations" "0.4.10" + "@firebase/logger" "0.2.4" + "@firebase/performance-types" "0.0.13" + "@firebase/util" "0.2.47" + tslib "1.11.1" + +"@firebase/polyfill@0.3.36": + version "0.3.36" + resolved "https://registry.yarnpkg.com/@firebase/polyfill/-/polyfill-0.3.36.tgz#c057cce6748170f36966b555749472b25efdb145" + integrity sha512-zMM9oSJgY6cT2jx3Ce9LYqb0eIpDE52meIzd/oe/y70F+v9u1LDqk5kUF5mf16zovGBWMNFmgzlsh6Wj0OsFtg== + dependencies: + core-js "3.6.5" + promise-polyfill "8.1.3" + whatwg-fetch "2.0.4" + +"@firebase/remote-config-types@0.1.9": + version "0.1.9" + resolved "https://registry.yarnpkg.com/@firebase/remote-config-types/-/remote-config-types-0.1.9.tgz#fe6bbe4d08f3b6e92fce30e4b7a9f4d6a96d6965" + integrity sha512-G96qnF3RYGbZsTRut7NBX0sxyczxt1uyCgXQuH/eAfUCngxjEGcZQnBdy6mvSdqdJh5mC31rWPO4v9/s7HwtzA== + +"@firebase/remote-config@0.1.21": + version "0.1.21" + resolved "https://registry.yarnpkg.com/@firebase/remote-config/-/remote-config-0.1.21.tgz#72261a53a7564453f484278e14ba39d81da99833" + integrity sha512-EwDNU1mT+8Jn66IUwwNP5SM8AbaI7wmCXjp7djZtTXNrpPoh3xqzSRM1vTgp4Uu/mHffEDfbydsoJAIftADIfQ== + dependencies: + "@firebase/component" "0.1.12" + "@firebase/installations" "0.4.10" + "@firebase/logger" "0.2.4" + "@firebase/remote-config-types" "0.1.9" + "@firebase/util" "0.2.47" + tslib "1.11.1" + +"@firebase/storage-types@0.3.12": + version "0.3.12" + resolved "https://registry.yarnpkg.com/@firebase/storage-types/-/storage-types-0.3.12.tgz#79540761fb3ad8d674c98712633284d81b268e0f" + integrity sha512-DDV6Fs6aYoGw3w/zZZTkqiipxihnsvHf6znbeZYjIIHit3tr1uLJdGPDPiCTfZcTGPpg2ux6ZmvNDvVgJdHALw== + +"@firebase/storage@0.3.34": + version "0.3.34" + resolved "https://registry.yarnpkg.com/@firebase/storage/-/storage-0.3.34.tgz#410ac7988f49259572e0e15c600548982ec5e904" + integrity sha512-vuR1PpGdaCk25D2dT2trfmZZjpdfOn0rPTksvoqg7TAPLeoVsVoDyT2LgF3Arna/jqx52sAIRx1HLrlvzE1pgA== + dependencies: + "@firebase/component" "0.1.12" + "@firebase/storage-types" "0.3.12" + "@firebase/util" "0.2.47" + tslib "1.11.1" + +"@firebase/util@0.2.47": + version "0.2.47" + resolved "https://registry.yarnpkg.com/@firebase/util/-/util-0.2.47.tgz#c5e02bbba7aa0786f29cc516b2e2ee17e0c1f4a4" + integrity sha512-RjcIvcfswyxYhf0OMXod+qeI/933wl9FGLIszf0/O1yMZ/s8moXcse7xnOpMjmQPRLB9vHzCMoxW5X90kKg/bQ== + dependencies: + tslib "1.11.1" + +"@firebase/webchannel-wrapper@0.2.41": + version "0.2.41" + resolved "https://registry.yarnpkg.com/@firebase/webchannel-wrapper/-/webchannel-wrapper-0.2.41.tgz#4e470c25a99fa0b1f629f1c5ef180a318d399fd0" + integrity sha512-XcdMT5PSZHiuf7LJIhzKIe+RyYa25S3LHRRvLnZc6iFjwXkrSDJ8J/HWO6VT8d2ZTbawp3VcLEjRF/VN8glCrA== + "@graphql-toolkit/common@0.10.4": version "0.10.4" resolved "https://registry.yarnpkg.com/@graphql-toolkit/common/-/common-0.10.4.tgz#7785f2a3f14559d0778859c49f4442078c196695" @@ -1150,6 +1373,21 @@ graphql-tools "5.0.0" tslib "1.11.1" +"@grpc/grpc-js@0.8.1": + version "0.8.1" + resolved "https://registry.yarnpkg.com/@grpc/grpc-js/-/grpc-js-0.8.1.tgz#3003a422577da39e7113566f2fdd4872f31e6090" + integrity sha512-e8gSjRZnOUefsR3obOgxG9RtYW2Mw83hh7ogE2ByCdgRhoX0mdnJwBcZOami3E0l643KCTZvORFwfSEi48KFIQ== + dependencies: + semver "^6.2.0" + +"@grpc/proto-loader@^0.5.0": + version "0.5.4" + resolved "https://registry.yarnpkg.com/@grpc/proto-loader/-/proto-loader-0.5.4.tgz#038a3820540f621eeb1b05d81fbedfb045e14de0" + integrity sha512-HTM4QpI9B2XFkPz7pjwMyMgZchJ93TVkL3kWPW8GDMDKYxsMnmf4w2TNMJK7+KNiYHS5cJrCEAFlF+AwtXWVPA== + dependencies: + lodash.camelcase "^4.3.0" + protobufjs "^6.8.6" + "@istanbuljs/load-nyc-config@^1.0.0": version "1.0.0" resolved "https://registry.yarnpkg.com/@istanbuljs/load-nyc-config/-/load-nyc-config-1.0.0.tgz#10602de5570baea82f8afbfa2630b24e7a8cfe5b" @@ -2709,7 +2947,7 @@ resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.150.tgz#649fe44684c3f1fcb6164d943c5a61977e8cf0bd" integrity sha512-kMNLM5JBcasgYscD9x/Gvr6lTAv2NVgsKtet/hm93qMyf/D1pt+7jeEZklKJKxMVmXjxbRVQQGfqDSfipYCO6w== -"@types/long@^4.0.0": +"@types/long@^4.0.0", "@types/long@^4.0.1": version "4.0.1" resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.1.tgz#459c65fa1867dafe6a8f322c4c51695663cc55e9" integrity sha512-5tXH6Bx/kNGd3MgffdmP4dy2Z+G4eaXw0SE81Tq3BNadtnMR5/ySMzX4SLEzHJzSmPNn4HIdpQsBvXMUykr58w== @@ -2764,6 +3002,11 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-10.17.21.tgz#c00e9603399126925806bed2d9a1e37da506965e" integrity sha512-PQKsydPxYxF1DsAFWmunaxd3sOi3iMt6Zmx/tgaagHYmwJ/9cRH91hQkeJZaUGWbvn0K5HlSVEXkn5U/llWPpQ== +"@types/node@^13.7.0": + version "13.13.9" + resolved "https://registry.yarnpkg.com/@types/node/-/node-13.13.9.tgz#79df4ae965fb76d31943b54a6419599307a21394" + integrity sha512-EPZBIGed5gNnfWCiwEIwTE2Jdg4813odnG8iNPMQGrqVxrI+wL68SPtPeCX+ZxGBaA6pKAVc6jaKgP/Q0QzfdQ== + "@types/normalize-package-data@^2.4.0": version "2.4.0" resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e" @@ -5231,7 +5474,7 @@ core-js@3.6.4: resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.6.4.tgz#440a83536b458114b9cb2ac1580ba377dc470647" integrity sha512-4paDGScNgZP2IXXilaffL9X7968RuvwlkK3xWtZRVqgd8SYNiVKRJvkFd1aqqEuPfN7E68ZHEp9hDj6lHj4Hyw== -core-js@^3.0.1, core-js@^3.2.1, core-js@^3.6.4: +core-js@3.6.5, core-js@^3.0.1, core-js@^3.2.1, core-js@^3.6.4: version "3.6.5" resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.6.5.tgz#7395dc273af37fb2e50e9bd3d9fe841285231d1a" integrity sha512-vZVEEwZoIsI+vPEuoF9Iqf5H7/M3eeQqWlQnYa8FSKKePuYTf5MWnxb5SDAzCa60b3JBRS5g9b+Dq7b1y/RCrA== @@ -5936,6 +6179,11 @@ dom-serializer@0, dom-serializer@^0.2.1: domelementtype "^2.0.1" entities "^2.0.0" +dom-storage@2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/dom-storage/-/dom-storage-2.1.0.tgz#00fb868bc9201357ea243c7bcfd3304c1e34ea39" + integrity sha512-g6RpyWXzl0RR6OTElHKBl7nwnK87GUyZMYC7JWsB/IA73vpqK2K6LT39x4VepLxlSsWBFrPVLnsSR5Jyty0+2Q== + domain-browser@^1.1.1: version "1.2.0" resolved "https://registry.yarnpkg.com/domain-browser/-/domain-browser-1.2.0.tgz#3d31f50191a6749dd1375a7f522e823d42e54eda" @@ -6831,6 +7079,13 @@ fastq@^1.6.0: dependencies: reusify "^1.0.4" +faye-websocket@0.11.3, faye-websocket@~0.11.1: + version "0.11.3" + resolved "https://registry.yarnpkg.com/faye-websocket/-/faye-websocket-0.11.3.tgz#5c0e9a8968e8912c286639fde977a8b209f2508e" + integrity sha512-D2y4bovYpzziGgbHYtGCMjlJM36vAl/y+xUyn1C+FVx8szd1E+86KwVw6XvYSzOP8iMpm1X0I4xJD+QtUb36OA== + dependencies: + websocket-driver ">=0.5.1" + faye-websocket@^0.10.0: version "0.10.0" resolved "https://registry.yarnpkg.com/faye-websocket/-/faye-websocket-0.10.0.tgz#4e492f8d04dfb6f89003507f6edbf2d501e7c6f4" @@ -6838,13 +7093,6 @@ faye-websocket@^0.10.0: dependencies: websocket-driver ">=0.5.1" -faye-websocket@~0.11.1: - version "0.11.3" - resolved "https://registry.yarnpkg.com/faye-websocket/-/faye-websocket-0.11.3.tgz#5c0e9a8968e8912c286639fde977a8b209f2508e" - integrity sha512-D2y4bovYpzziGgbHYtGCMjlJM36vAl/y+xUyn1C+FVx8szd1E+86KwVw6XvYSzOP8iMpm1X0I4xJD+QtUb36OA== - dependencies: - websocket-driver ">=0.5.1" - fb-watchman@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/fb-watchman/-/fb-watchman-2.0.1.tgz#fc84fb39d2709cf3ff6d743706157bb5708a8a85" @@ -7032,6 +7280,26 @@ findup-sync@^4.0.0: micromatch "^4.0.2" resolve-dir "^1.0.1" +firebase@^7.14.5: + version "7.14.5" + resolved "https://registry.yarnpkg.com/firebase/-/firebase-7.14.5.tgz#cf1be9c7f0603c6c2f45f65c7d817f6b22114a4b" + integrity sha512-1vrC1UZIVhaT7owaElQoEseP81xqRt6tHQmxRJRojn0yI3JNXrdWCFsD+26xA1eQQCwodJuMsYJLzQSScgjHuQ== + dependencies: + "@firebase/analytics" "0.3.5" + "@firebase/app" "0.6.4" + "@firebase/app-types" "0.6.1" + "@firebase/auth" "0.14.6" + "@firebase/database" "0.6.3" + "@firebase/firestore" "1.14.5" + "@firebase/functions" "0.4.44" + "@firebase/installations" "0.4.10" + "@firebase/messaging" "0.6.16" + "@firebase/performance" "0.3.4" + "@firebase/polyfill" "0.3.36" + "@firebase/remote-config" "0.1.21" + "@firebase/storage" "0.3.34" + "@firebase/util" "0.2.47" + flat-cache@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-2.0.1.tgz#5d296d6f04bda44a4630a301413bdbc2ec085ec0" @@ -8031,6 +8299,11 @@ icss-utils@^4.0.0, icss-utils@^4.1.1: dependencies: postcss "^7.0.14" +idb@3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/idb/-/idb-3.0.2.tgz#c8e9122d5ddd40f13b60ae665e4862f8b13fa384" + integrity sha512-+FLa/0sTXqyux0o6C+i2lOR0VoS60LU/jzUo5xjfY6+7sEEgy4Gz1O7yFBXvjd7N0NyIGWIRg8DcQSLEG+VSPw== + ieee754@^1.1.4: version "1.1.13" resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.13.tgz#ec168558e95aa181fd87d37f55c32bbcb6708b84" @@ -8581,7 +8854,7 @@ is-ssh@^1.3.0: dependencies: protocols "^1.1.0" -is-stream@^1.1.0: +is-stream@^1.0.1, is-stream@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" integrity sha1-EtSj3U5o4Lec6428hBc66A2RykQ= @@ -8674,6 +8947,14 @@ isobject@^4.0.0: resolved "https://registry.yarnpkg.com/isobject/-/isobject-4.0.0.tgz#3f1c9155e73b192022a80819bacd0343711697b0" integrity sha512-S/2fF5wH8SJA/kmwr6HYhK/RI/OkhD84k8ntalo0iJjZikgq1XFvR5M8NPT1x5F7fBwCG3qHfnzeP/Vh/ZxCUA== +isomorphic-fetch@2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9" + integrity sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk= + dependencies: + node-fetch "^1.0.1" + whatwg-fetch ">=0.10.0" + isstream@~0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a" @@ -9575,6 +9856,11 @@ lodash._reinterpolate@^3.0.0: resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d" integrity sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0= +lodash.camelcase@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6" + integrity sha1-soqmKIorn8ZRA1x3EfZathkDMaY= + lodash.clonedeep@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef" @@ -10390,6 +10676,14 @@ node-fetch@2.6.0, node-fetch@^2.1.2, node-fetch@^2.2.0, node-fetch@^2.3.0, node- resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd" integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA== +node-fetch@^1.0.1: + version "1.7.3" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef" + integrity sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ== + dependencies: + encoding "^0.1.11" + is-stream "^1.0.1" + node-forge@0.9.0: version "0.9.0" resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.9.0.tgz#d624050edbb44874adca12bb9a52ec63cb782579" @@ -11486,7 +11780,7 @@ promise-inflight@^1.0.1: resolved "https://registry.yarnpkg.com/promise-inflight/-/promise-inflight-1.0.1.tgz#98472870bf228132fcbdd868129bad12c3c029e3" integrity sha1-mEcocL8igTL8vdhoEputEsPAKeM= -promise-polyfill@^8.1.3: +promise-polyfill@8.1.3, promise-polyfill@^8.1.3: version "8.1.3" resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-8.1.3.tgz#8c99b3cf53f3a91c68226ffde7bde81d7f904116" integrity sha512-MG5r82wBzh7pSKDRa9y+vllNHz3e3d4CNj1PQE4BQYxLme0gKYYBm9YENq+UkEikyZ0XbiGWxYlVw3Rl9O/U8g== @@ -11533,6 +11827,25 @@ proto-list@~1.2.1: resolved "https://registry.yarnpkg.com/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849" integrity sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk= +protobufjs@^6.8.6: + version "6.9.0" + resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-6.9.0.tgz#c08b2bf636682598e6fabbf0edb0b1256ff090bd" + integrity sha512-LlGVfEWDXoI/STstRDdZZKb/qusoAWUnmLg9R8OLSO473mBLWHowx8clbX5/+mKDEI+v7GzjoK9tRPZMMcoTrg== + dependencies: + "@protobufjs/aspromise" "^1.1.2" + "@protobufjs/base64" "^1.1.2" + "@protobufjs/codegen" "^2.0.4" + "@protobufjs/eventemitter" "^1.1.0" + "@protobufjs/fetch" "^1.1.0" + "@protobufjs/float" "^1.0.2" + "@protobufjs/inquire" "^1.1.0" + "@protobufjs/path" "^1.1.2" + "@protobufjs/pool" "^1.1.0" + "@protobufjs/utf8" "^1.1.0" + "@types/long" "^4.0.1" + "@types/node" "^13.7.0" + long "^4.0.0" + protocols@^1.1.0, protocols@^1.4.0: version "1.4.7" resolved "https://registry.yarnpkg.com/protocols/-/protocols-1.4.7.tgz#95f788a4f0e979b291ffefcf5636ad113d037d32" @@ -14286,7 +14599,12 @@ whatwg-encoding@^1.0.1, whatwg-encoding@^1.0.5: dependencies: iconv-lite "0.4.24" -whatwg-fetch@3.0.0: +whatwg-fetch@2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz#dde6a5df315f9d39991aa17621853d720b85566f" + integrity sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng== + +whatwg-fetch@3.0.0, whatwg-fetch@>=0.10.0: version "3.0.0" resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz#fc804e458cc460009b1a2b966bc8817d2578aefb" integrity sha512-9GSJUgz1D4MfyKU7KRqwOjXCXTqWdFNvEr7eUBYchQiVc744mqK/MzXPNR2WsPkmkOa4ywfg8C2n8h+13Bey1Q== @@ -14525,6 +14843,11 @@ xmlchars@^2.1.1: resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb" integrity sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw== +xmlhttprequest@1.8.0: + version "1.8.0" + resolved "https://registry.yarnpkg.com/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz#67fe075c5c24fef39f9d65f5f7b7fe75171968fc" + integrity sha1-Z/4HXFwk/vOfnWX197f+dRcZaPw= + xregexp@4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/xregexp/-/xregexp-4.0.0.tgz#e698189de49dd2a18cc5687b05e17c8e43943020" From 4fed355d0c468f1a98dee31f82d81540467df667 Mon Sep 17 00:00:00 2001 From: Thomas Seillan Date: Sun, 24 May 2020 15:39:30 +0200 Subject: [PATCH 2/3] Fixed formatting errors. Sorry. --- packages/auth/src/authClient.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/auth/src/authClient.ts b/packages/auth/src/authClient.ts index e1bb7801dff2..e0ab9c080dca 100644 --- a/packages/auth/src/authClient.ts +++ b/packages/auth/src/authClient.ts @@ -41,11 +41,11 @@ const mapAuthClientAuth0 = (client: Auth0): AuthClientAuth0 => { if (window.location.search.includes('code=')) { const { appState } = await client.handleRedirectCallback() window.history.replaceState( - {}, - document.title, - appState && appState.targetUrl - ? appState.targetUrl - : window.location.pathname + {}, + document.title, + appState && appState.targetUrl + ? appState.targetUrl + : window.location.pathname ) } }, @@ -64,7 +64,7 @@ const mapAuthClientGoTrue = (client: GoTrue): AuthClientGoTrue => { type: 'gotrue', client, login: async ({ email, password, remember }) => - client.login(email, password, remember), + client.login(email, password, remember), logout: async () => { const user = await client.currentUser() return user?.logout() @@ -130,12 +130,12 @@ const mapAuthClientFirebase = (client: Firebase): AuthClient => { } export const createAuthClient = ( - client: SupportedAuthClients, - type: SupportedAuthTypes + client: SupportedAuthClients, + type: SupportedAuthTypes ): AuthClient => { switch (type) { case 'firebase': - return mapAuthClientFirebase(client as Firebase); + return mapAuthClientFirebase(client as Firebase) case 'auth0': return mapAuthClientAuth0(client as Auth0) case 'gotrue': @@ -144,7 +144,7 @@ export const createAuthClient = ( return mapAuthClientNetlify(client as NetlifyIdentity) default: throw new Error( - `The ${type} auth client is not currently supported, please consider adding it.` + `The ${type} auth client is not currently supported, please consider adding it.` ) } } From e73802ff83f6ee1486e0ffb30704509a41d46c45 Mon Sep 17 00:00:00 2001 From: Thomas Seillan Date: Tue, 26 May 2020 08:15:03 +0200 Subject: [PATCH 3/3] Added firebase to authHeaders.ts for API side + fixed missing client in authClient.ts --- packages/api/src/auth/authHeaders.ts | 5 ++++- packages/auth/src/authClient.ts | 17 ++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/api/src/auth/authHeaders.ts b/packages/api/src/auth/authHeaders.ts index b2cf8999c302..53f29d3b3511 100644 --- a/packages/api/src/auth/authHeaders.ts +++ b/packages/api/src/auth/authHeaders.ts @@ -9,7 +9,7 @@ import { AuthenticationError } from 'apollo-server-lambda' import { verifyAuth0Token } from './verifyAuth0Token' -export type SupportedAuthTypes = 'auth0' | 'netlify' | 'gotrue' +export type SupportedAuthTypes = 'auth0' | 'firebase' | 'netlify' | 'gotrue' // This is shared by `@redwoodjs/web` const AUTH_PROVIDER_HEADER = 'auth-provider' @@ -67,6 +67,9 @@ export const decodeAuthToken = async ({ } break } + case 'firebase': + decoded = token + break case 'auth0': { decoded = await verifyAuth0Token(token) break diff --git a/packages/auth/src/authClient.ts b/packages/auth/src/authClient.ts index e0ab9c080dca..1a63ec21a0c5 100644 --- a/packages/auth/src/authClient.ts +++ b/packages/auth/src/authClient.ts @@ -1,15 +1,18 @@ import type { default as GoTrue, User as GoTrueUser } from 'gotrue-js' import type { Auth0Client as Auth0 } from '@auth0/auth0-spa-js' import type NetlifyIdentityNS from 'netlify-identity-widget' -// TODO: Import missing Firebase type +import * as firebase from 'firebase/app' // TODO: Can also return an Auth0 user which doesn't have a definition. // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface Auth0User {} export type { GoTrueUser } export type NetlifyIdentity = typeof NetlifyIdentityNS - -// TODO: Add missing Firebase Type -export type SupportedAuthClients = Auth0 | GoTrue | NetlifyIdentity +export type FirebaseClient = typeof firebase +export type SupportedAuthClients = + | Auth0 + | FirebaseClient + | GoTrue + | NetlifyIdentity export type SupportedAuthTypes = 'auth0' | 'firebase' | 'gotrue' | 'netlify' export interface AuthClient { @@ -114,7 +117,7 @@ const mapAuthClientNetlify = (client: NetlifyIdentity): AuthClient => { } } -const mapAuthClientFirebase = (client: Firebase): AuthClient => { +const mapAuthClientFirebase = (client: FirebaseClient): AuthClient => { return { type: 'firebase', client, @@ -124,7 +127,7 @@ const mapAuthClientFirebase = (client: Firebase): AuthClient => { return client.auth().signInWithRedirect(provider) }, logout: () => client.auth().signOut(), - getToken: async () => client.auth().currentUser.getIdToken(), + getToken: async () => client.auth().currentUser?.getIdToken() ?? null, currentUser: async () => client.auth().currentUser, } } @@ -135,7 +138,7 @@ export const createAuthClient = ( ): AuthClient => { switch (type) { case 'firebase': - return mapAuthClientFirebase(client as Firebase) + return mapAuthClientFirebase(client as FirebaseClient) case 'auth0': return mapAuthClientAuth0(client as Auth0) case 'gotrue':