Skip to content

Commit

Permalink
Add polyfill to globalThis
Browse files Browse the repository at this point in the history
fix: #38
  • Loading branch information
kiwicopple committed Jan 14, 2021
1 parent 57001d5 commit 02c4d19
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions src/lib/polyfills.ts
Original file line number Diff line number Diff line change
@@ -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__
}

0 comments on commit 02c4d19

Please sign in to comment.