Skip to content

Commit

Permalink
temporary enforce the atob polyfill for React Native
Browse files Browse the repository at this point in the history
  • Loading branch information
ganigeorgiev committed May 31, 2024
1 parent 04f9ae5 commit ed02577
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.21.3

- Enforce temporary the `atob` polyfill for ReactNative until [Expo 51+ and React Native v0.17+ `atob` fix get released](https://github.com/reactwg/react-native-releases/issues/287).


## 0.21.2

- Exported `HealthService` types ([#289](https://github.com/pocketbase/js-sdk/issues/289)).
Expand Down
2 changes: 1 addition & 1 deletion dist/pocketbase.cjs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.cjs.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.es.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.es.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.es.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.es.mjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.iife.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.iife.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pocketbase.umd.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.21.2",
"version": "0.21.3",
"name": "pocketbase",
"description": "PocketBase JavaScript SDK",
"author": "Gani Georgiev",
Expand Down
16 changes: 11 additions & 5 deletions src/stores/utils/jwt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// @todo remove after https://github.com/reactwg/react-native-releases/issues/287
const isReactNative = (
(typeof navigator !== 'undefined' && navigator.product === 'ReactNative') ||
(typeof global !== 'undefined' && (global as any).HermesInternal)
);

let atobPolyfill: Function;
if (typeof atob === "function") {
if (typeof atob === "function" && !isReactNative) {
atobPolyfill = atob;
} else {
/**
Expand All @@ -23,10 +29,10 @@ if (typeof atob === "function") {
(buffer = str.charAt(idx++));
// character found in table? initialize bit storage and add its ascii value;
~buffer &&
((bs = bc % 4 ? (bs as any) * 64 + buffer : buffer),
// and if not first of each 4 characters,
// convert the first 8 bits to one ascii character
bc++ % 4)
((bs = bc % 4 ? (bs as any) * 64 + buffer : buffer),
// and if not first of each 4 characters,
// convert the first 8 bits to one ascii character
bc++ % 4)
? (output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6))))
: 0
) {
Expand Down

0 comments on commit ed02577

Please sign in to comment.