From 02c4d19e596b10b3d283895727b918d74670226a Mon Sep 17 00:00:00 2001 From: Paul Copplestone Date: Thu, 14 Jan 2021 18:22:45 +0800 Subject: [PATCH 1/2] Add polyfill to globalThis fix: #38 --- src/GoTrueClient.ts | 3 +++ src/lib/polyfills.ts | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/lib/polyfills.ts diff --git a/src/GoTrueClient.ts b/src/GoTrueClient.ts index e91234c30..7ec8de9db 100644 --- a/src/GoTrueClient.ts +++ b/src/GoTrueClient.ts @@ -10,6 +10,9 @@ import { AuthChangeEvent, CookieOptions, } from './lib/types' +import { polyfillGlobalThis } from './lib/polyfills' + +polyfillGlobalThis() // Make "globalThis" available const DEFAULT_OPTIONS = { url: GOTRUE_URL, diff --git a/src/lib/polyfills.ts b/src/lib/polyfills.ts new file mode 100644 index 000000000..6ab243ea8 --- /dev/null +++ b/src/lib/polyfills.ts @@ -0,0 +1,16 @@ +// @ts-nocheck + +/** + * https://mathiasbynens.be/notes/globalthis + */ +export function polyfillGlobalThis() { + if (typeof globalThis === 'object') return + Object.defineProperty(Object.prototype, '__magic__', { + get: function () { + return this + }, + configurable: true, + }) + __magic__.globalThis = __magic__ + delete Object.prototype.__magic__ +} From 82ffec960dd566d2a6dc7839ca0d20355236237d Mon Sep 17 00:00:00 2001 From: Paul Copplestone Date: Thu, 14 Jan 2021 18:25:37 +0800 Subject: [PATCH 2/2] removes process.env from lib. Users can override in the constructor fix: #41 --- src/lib/constants.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 381282c61..2003ad769 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -1,8 +1,8 @@ -export const GOTRUE_URL = process?.env?.GOTRUE_URL || 'http://localhost:9999' -export const AUDIENCE = process?.env?.AUDIENCE || '' +export const GOTRUE_URL = 'http://localhost:9999' +export const AUDIENCE = '' export const DEFAULT_HEADERS = {} -export const EXPIRY_MARGIN = process?.env?.EXPIRY_MARGIN || 60 * 1000 -export const STORAGE_KEY = process?.env?.STORAGE_KEY || 'supabase.auth.token' +export const EXPIRY_MARGIN = 60 * 1000 +export const STORAGE_KEY = 'supabase.auth.token' export const COOKIE_OPTIONS = { name: 'sb:token', lifetime: 60 * 60 * 8,