Skip to content

Commit 8ec8530

Browse files
committed
fixed authWithOAuth2 cancellation
1 parent ab68644 commit 8ec8530

18 files changed

+248
-95
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.21.4
2+
3+
- Fixed the `requestKey` handling in `authWithOAuth2({...})` to allow manually cancelling the entire OAuth2 pending request flow using `pb.cancelRequest(requestKey)`.
4+
_Due to the [`window.close` caveats](https://developer.mozilla.org/en-US/docs/Web/API/Window/close) note that the OAuth2 popup window may still remain open depending on which stage of the OAuth2 flow the cancellation has been invoked._
5+
6+
17
## 0.21.3
28

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

dist/pocketbase.cjs.d.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,10 +776,31 @@ declare class RecordService<M = RecordModel> extends CrudService<M> {
776776
* })
777777
* ```
778778
*
779-
* _Site-note_: when creating the OAuth2 app in the provider dashboard
779+
* Note1: When creating the OAuth2 app in the provider dashboard
780780
* you have to configure `https://yourdomain.com/api/oauth2-redirect`
781781
* as redirect URL.
782782
*
783+
* Note2: Safari may block the default `urlCallback` popup because
784+
* it doesn't allow `window.open` calls as part of an `async` click functions.
785+
* To workaround this you can either change your click handler to not be marked as `async`
786+
* OR manually call `window.open` before your `async` function and use the
787+
* window reference in your own custom `urlCallback` (see https://github.com/pocketbase/pocketbase/discussions/2429#discussioncomment-5943061).
788+
* For example:
789+
* ```js
790+
* <button id="btn">Login with Gitlab</button>
791+
* ...
792+
* document.getElementById("btn").addEventListener("click", () => {
793+
* pb.collection("users").authWithOAuth2({
794+
* provider: "gitlab",
795+
* }).then((authData) => {
796+
* console.log(authData)
797+
* }).catch((err) => {
798+
* console.log(err, err.originalError);
799+
* });
800+
* })
801+
* ```
802+
*
803+
*
783804
* @throws {ClientResponseError}
784805
*/
785806
authWithOAuth2<T = M>(options: OAuth2AuthConfig): Promise<RecordAuthResponse<T>>;

dist/pocketbase.cjs.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pocketbase.cjs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pocketbase.es.d.mts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,10 +799,31 @@ declare class RecordService<M = RecordModel> extends CrudService<M> {
799799
* })
800800
* ```
801801
*
802-
* _Site-note_: when creating the OAuth2 app in the provider dashboard
802+
* Note1: When creating the OAuth2 app in the provider dashboard
803803
* you have to configure `https://yourdomain.com/api/oauth2-redirect`
804804
* as redirect URL.
805805
*
806+
* Note2: Safari may block the default `urlCallback` popup because
807+
* it doesn't allow `window.open` calls as part of an `async` click functions.
808+
* To workaround this you can either change your click handler to not be marked as `async`
809+
* OR manually call `window.open` before your `async` function and use the
810+
* window reference in your own custom `urlCallback` (see https://github.com/pocketbase/pocketbase/discussions/2429#discussioncomment-5943061).
811+
* For example:
812+
* ```js
813+
* <button id="btn">Login with Gitlab</button>
814+
* ...
815+
* document.getElementById("btn").addEventListener("click", () => {
816+
* pb.collection("users").authWithOAuth2({
817+
* provider: "gitlab",
818+
* }).then((authData) => {
819+
* console.log(authData)
820+
* }).catch((err) => {
821+
* console.log(err, err.originalError);
822+
* });
823+
* })
824+
* ```
825+
*
826+
*
806827
* @throws {ClientResponseError}
807828
*/
808829
authWithOAuth2<T = M>(options: OAuth2AuthConfig): Promise<RecordAuthResponse<T>>;

dist/pocketbase.es.d.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,10 +799,31 @@ declare class RecordService<M = RecordModel> extends CrudService<M> {
799799
* })
800800
* ```
801801
*
802-
* _Site-note_: when creating the OAuth2 app in the provider dashboard
802+
* Note1: When creating the OAuth2 app in the provider dashboard
803803
* you have to configure `https://yourdomain.com/api/oauth2-redirect`
804804
* as redirect URL.
805805
*
806+
* Note2: Safari may block the default `urlCallback` popup because
807+
* it doesn't allow `window.open` calls as part of an `async` click functions.
808+
* To workaround this you can either change your click handler to not be marked as `async`
809+
* OR manually call `window.open` before your `async` function and use the
810+
* window reference in your own custom `urlCallback` (see https://github.com/pocketbase/pocketbase/discussions/2429#discussioncomment-5943061).
811+
* For example:
812+
* ```js
813+
* <button id="btn">Login with Gitlab</button>
814+
* ...
815+
* document.getElementById("btn").addEventListener("click", () => {
816+
* pb.collection("users").authWithOAuth2({
817+
* provider: "gitlab",
818+
* }).then((authData) => {
819+
* console.log(authData)
820+
* }).catch((err) => {
821+
* console.log(err, err.originalError);
822+
* });
823+
* })
824+
* ```
825+
*
826+
*
806827
* @throws {ClientResponseError}
807828
*/
808829
authWithOAuth2<T = M>(options: OAuth2AuthConfig): Promise<RecordAuthResponse<T>>;

dist/pocketbase.es.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pocketbase.es.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pocketbase.es.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/pocketbase.es.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pocketbase.iife.d.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,10 +776,31 @@ declare class RecordService<M = RecordModel> extends CrudService<M> {
776776
* })
777777
* ```
778778
*
779-
* _Site-note_: when creating the OAuth2 app in the provider dashboard
779+
* Note1: When creating the OAuth2 app in the provider dashboard
780780
* you have to configure `https://yourdomain.com/api/oauth2-redirect`
781781
* as redirect URL.
782782
*
783+
* Note2: Safari may block the default `urlCallback` popup because
784+
* it doesn't allow `window.open` calls as part of an `async` click functions.
785+
* To workaround this you can either change your click handler to not be marked as `async`
786+
* OR manually call `window.open` before your `async` function and use the
787+
* window reference in your own custom `urlCallback` (see https://github.com/pocketbase/pocketbase/discussions/2429#discussioncomment-5943061).
788+
* For example:
789+
* ```js
790+
* <button id="btn">Login with Gitlab</button>
791+
* ...
792+
* document.getElementById("btn").addEventListener("click", () => {
793+
* pb.collection("users").authWithOAuth2({
794+
* provider: "gitlab",
795+
* }).then((authData) => {
796+
* console.log(authData)
797+
* }).catch((err) => {
798+
* console.log(err, err.originalError);
799+
* });
800+
* })
801+
* ```
802+
*
803+
*
783804
* @throws {ClientResponseError}
784805
*/
785806
authWithOAuth2<T = M>(options: OAuth2AuthConfig): Promise<RecordAuthResponse<T>>;

dist/pocketbase.iife.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pocketbase.iife.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pocketbase.umd.d.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,10 +776,31 @@ declare class RecordService<M = RecordModel> extends CrudService<M> {
776776
* })
777777
* ```
778778
*
779-
* _Site-note_: when creating the OAuth2 app in the provider dashboard
779+
* Note1: When creating the OAuth2 app in the provider dashboard
780780
* you have to configure `https://yourdomain.com/api/oauth2-redirect`
781781
* as redirect URL.
782782
*
783+
* Note2: Safari may block the default `urlCallback` popup because
784+
* it doesn't allow `window.open` calls as part of an `async` click functions.
785+
* To workaround this you can either change your click handler to not be marked as `async`
786+
* OR manually call `window.open` before your `async` function and use the
787+
* window reference in your own custom `urlCallback` (see https://github.com/pocketbase/pocketbase/discussions/2429#discussioncomment-5943061).
788+
* For example:
789+
* ```js
790+
* <button id="btn">Login with Gitlab</button>
791+
* ...
792+
* document.getElementById("btn").addEventListener("click", () => {
793+
* pb.collection("users").authWithOAuth2({
794+
* provider: "gitlab",
795+
* }).then((authData) => {
796+
* console.log(authData)
797+
* }).catch((err) => {
798+
* console.log(err, err.originalError);
799+
* });
800+
* })
801+
* ```
802+
*
803+
*
783804
* @throws {ClientResponseError}
784805
*/
785806
authWithOAuth2<T = M>(options: OAuth2AuthConfig): Promise<RecordAuthResponse<T>>;

dist/pocketbase.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pocketbase.umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.21.3",
2+
"version": "0.21.4",
33
"name": "pocketbase",
44
"description": "PocketBase JavaScript SDK",
55
"author": "Gani Georgiev",

0 commit comments

Comments
 (0)