react-native-nitro-auth 0.5.4 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +82 -47
  2. package/android/proguard-rules.pro +7 -1
  3. package/android/src/main/AndroidManifest.xml +12 -0
  4. package/android/src/main/cpp/JniOnLoad.cpp +3 -1
  5. package/android/src/main/cpp/PlatformAuth+Android.cpp +271 -78
  6. package/android/src/main/java/com/auth/AuthAdapter.kt +293 -238
  7. package/android/src/main/java/com/auth/GoogleSignInActivity.kt +9 -5
  8. package/android/src/main/java/com/auth/NitroAuthModule.kt +8 -1
  9. package/cpp/HybridAuth.cpp +79 -64
  10. package/cpp/HybridAuth.hpp +9 -7
  11. package/cpp/JSONSerializer.hpp +3 -0
  12. package/ios/AuthAdapter.swift +226 -79
  13. package/ios/PlatformAuth+iOS.mm +10 -3
  14. package/lib/commonjs/Auth.web.js +50 -10
  15. package/lib/commonjs/Auth.web.js.map +1 -1
  16. package/lib/commonjs/index.js +23 -1
  17. package/lib/commonjs/index.js.map +1 -1
  18. package/lib/commonjs/index.web.js +30 -12
  19. package/lib/commonjs/index.web.js.map +1 -1
  20. package/lib/commonjs/service.js +36 -9
  21. package/lib/commonjs/service.js.map +1 -1
  22. package/lib/commonjs/service.web.js +65 -13
  23. package/lib/commonjs/service.web.js.map +1 -1
  24. package/lib/commonjs/ui/social-button.js +19 -14
  25. package/lib/commonjs/ui/social-button.js.map +1 -1
  26. package/lib/commonjs/ui/social-button.web.js +16 -10
  27. package/lib/commonjs/ui/social-button.web.js.map +1 -1
  28. package/lib/commonjs/use-auth.js +22 -25
  29. package/lib/commonjs/use-auth.js.map +1 -1
  30. package/lib/commonjs/utils/auth-error.js +37 -0
  31. package/lib/commonjs/utils/auth-error.js.map +1 -0
  32. package/lib/commonjs/utils/logger.js +1 -0
  33. package/lib/commonjs/utils/logger.js.map +1 -1
  34. package/lib/module/Auth.web.js +50 -10
  35. package/lib/module/Auth.web.js.map +1 -1
  36. package/lib/module/global.d.js.map +1 -1
  37. package/lib/module/index.js +1 -0
  38. package/lib/module/index.js.map +1 -1
  39. package/lib/module/index.web.js +2 -1
  40. package/lib/module/index.web.js.map +1 -1
  41. package/lib/module/service.js +36 -9
  42. package/lib/module/service.js.map +1 -1
  43. package/lib/module/service.web.js +65 -13
  44. package/lib/module/service.web.js.map +1 -1
  45. package/lib/module/ui/social-button.js +19 -14
  46. package/lib/module/ui/social-button.js.map +1 -1
  47. package/lib/module/ui/social-button.web.js +16 -10
  48. package/lib/module/ui/social-button.web.js.map +1 -1
  49. package/lib/module/use-auth.js +22 -25
  50. package/lib/module/use-auth.js.map +1 -1
  51. package/lib/module/utils/auth-error.js +30 -0
  52. package/lib/module/utils/auth-error.js.map +1 -0
  53. package/lib/module/utils/logger.js +1 -0
  54. package/lib/module/utils/logger.js.map +1 -1
  55. package/lib/typescript/commonjs/Auth.web.d.ts +5 -1
  56. package/lib/typescript/commonjs/Auth.web.d.ts.map +1 -1
  57. package/lib/typescript/commonjs/index.d.ts +1 -0
  58. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  59. package/lib/typescript/commonjs/index.web.d.ts +2 -1
  60. package/lib/typescript/commonjs/index.web.d.ts.map +1 -1
  61. package/lib/typescript/commonjs/service.d.ts.map +1 -1
  62. package/lib/typescript/commonjs/service.web.d.ts +2 -18
  63. package/lib/typescript/commonjs/service.web.d.ts.map +1 -1
  64. package/lib/typescript/commonjs/ui/social-button.d.ts.map +1 -1
  65. package/lib/typescript/commonjs/ui/social-button.web.d.ts.map +1 -1
  66. package/lib/typescript/commonjs/use-auth.d.ts +2 -1
  67. package/lib/typescript/commonjs/use-auth.d.ts.map +1 -1
  68. package/lib/typescript/commonjs/utils/auth-error.d.ts +16 -0
  69. package/lib/typescript/commonjs/utils/auth-error.d.ts.map +1 -0
  70. package/lib/typescript/commonjs/utils/logger.d.ts.map +1 -1
  71. package/lib/typescript/module/Auth.web.d.ts +5 -1
  72. package/lib/typescript/module/Auth.web.d.ts.map +1 -1
  73. package/lib/typescript/module/index.d.ts +1 -0
  74. package/lib/typescript/module/index.d.ts.map +1 -1
  75. package/lib/typescript/module/index.web.d.ts +2 -1
  76. package/lib/typescript/module/index.web.d.ts.map +1 -1
  77. package/lib/typescript/module/service.d.ts.map +1 -1
  78. package/lib/typescript/module/service.web.d.ts +2 -18
  79. package/lib/typescript/module/service.web.d.ts.map +1 -1
  80. package/lib/typescript/module/ui/social-button.d.ts.map +1 -1
  81. package/lib/typescript/module/ui/social-button.web.d.ts.map +1 -1
  82. package/lib/typescript/module/use-auth.d.ts +2 -1
  83. package/lib/typescript/module/use-auth.d.ts.map +1 -1
  84. package/lib/typescript/module/utils/auth-error.d.ts +16 -0
  85. package/lib/typescript/module/utils/auth-error.d.ts.map +1 -0
  86. package/lib/typescript/module/utils/logger.d.ts.map +1 -1
  87. package/nitrogen/generated/android/NitroAuthOnLoad.cpp +22 -17
  88. package/nitrogen/generated/android/NitroAuthOnLoad.hpp +13 -4
  89. package/package.json +8 -10
  90. package/src/Auth.web.ts +77 -11
  91. package/src/global.d.ts +0 -11
  92. package/src/index.ts +5 -0
  93. package/src/index.web.ts +6 -1
  94. package/src/service.ts +37 -9
  95. package/src/service.web.ts +84 -15
  96. package/src/ui/social-button.tsx +21 -9
  97. package/src/ui/social-button.web.tsx +17 -4
  98. package/src/use-auth.ts +29 -67
  99. package/src/utils/auth-error.ts +49 -0
  100. package/src/utils/logger.ts +1 -0
@@ -2,4 +2,5 @@ export * from "./Auth.nitro";
2
2
  export * from "./ui/social-button";
3
3
  export { useAuth, type UseAuthReturn } from "./use-auth";
4
4
  export { AuthService } from "./service";
5
+ export { AuthError, isAuthErrorCode, toAuthErrorCode, } from "./utils/auth-error";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EACL,SAAS,EACT,eAAe,EACf,eAAe,GAChB,MAAM,oBAAoB,CAAC"}
@@ -1,5 +1,6 @@
1
1
  export * from "./Auth.nitro";
2
2
  export * from "./ui/social-button.web";
3
- export * from "./use-auth";
3
+ export { useAuth, type UseAuthReturn } from "./use-auth";
4
4
  export { AuthService } from "./service.web";
5
+ export { AuthError, isAuthErrorCode, toAuthErrorCode, } from "./utils/auth-error";
5
6
  //# sourceMappingURL=index.web.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../src/index.web.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../src/index.web.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACL,SAAS,EACT,eAAe,EACf,eAAe,GAChB,MAAM,oBAAoB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,IAAI,EAKL,MAAM,cAAc,CAAC;AAGtB,eAAO,MAAM,WAAW,EAAE,IAkEzB,CAAC"}
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,IAAI,EAKL,MAAM,cAAc,CAAC;AAKtB,eAAO,MAAM,WAAW,EAAE,IA4FzB,CAAC"}
@@ -1,19 +1,3 @@
1
- export declare const AuthService: {
2
- name: string;
3
- currentUser: import("./Auth.nitro").AuthUser | undefined;
4
- grantedScopes: string[];
5
- hasPlayServices: boolean;
6
- login: (provider: import("./Auth.nitro").AuthProvider, options?: import("./Auth.nitro").LoginOptions) => Promise<void>;
7
- logout: () => void;
8
- requestScopes: (scopes: string[]) => Promise<void>;
9
- revokeScopes: (scopes: string[]) => Promise<void>;
10
- getAccessToken: () => Promise<string | undefined>;
11
- refreshToken: () => Promise<import("./Auth.nitro").AuthTokens>;
12
- silentRestore: () => Promise<void>;
13
- onAuthStateChanged: (callback: (user: import("./Auth.nitro").AuthUser | undefined) => void) => () => void;
14
- onTokensRefreshed: (callback: (tokens: import("./Auth.nitro").AuthTokens) => void) => () => void;
15
- setLoggingEnabled: (enabled: boolean) => void;
16
- dispose: () => void;
17
- equals: (other: unknown) => boolean;
18
- };
1
+ import type { Auth } from "./Auth.nitro";
2
+ export declare const AuthService: Auth;
19
3
  //# sourceMappingURL=service.web.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"service.web.d.ts","sourceRoot":"","sources":["../../../src/service.web.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;CA+BvB,CAAC"}
1
+ {"version":3,"file":"service.web.d.ts","sourceRoot":"","sources":["../../../src/service.web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EAKL,MAAM,cAAc,CAAC;AAItB,eAAO,MAAM,WAAW,EAAE,IA4FzB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"social-button.d.ts","sourceRoot":"","sources":["../../../../src/ui/social-button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AASzD,OAAO,KAAK,EAAQ,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAElE,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAE5E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;IACrC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAsCF,eAAO,MAAM,YAAY,GAAI,+FAU1B,iBAAiB,sBAiFnB,CAAC"}
1
+ {"version":3,"file":"social-button.d.ts","sourceRoot":"","sources":["../../../../src/ui/social-button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAUzD,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE5D,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAE5E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;IACrC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAqCF,eAAO,MAAM,YAAY,GAAI,+FAU1B,iBAAiB,sBAuFnB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"social-button.web.d.ts","sourceRoot":"","sources":["../../../../src/ui/social-button.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AASzD,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE5D,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAE5E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;IACrC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAqCF,eAAO,MAAM,YAAY,GAAI,+FAU1B,iBAAiB,sBAiFnB,CAAC"}
1
+ {"version":3,"file":"social-button.web.d.ts","sourceRoot":"","sources":["../../../../src/ui/social-button.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAUzD,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE5D,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAE5E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;IACrC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAqCF,eAAO,MAAM,YAAY,GAAI,+FAU1B,iBAAiB,sBAuFnB,CAAC"}
@@ -1,9 +1,10 @@
1
1
  import type { AuthUser, AuthProvider, LoginOptions, AuthTokens } from "./Auth.nitro";
2
+ import { AuthError } from "./utils/auth-error";
2
3
  type AuthState = {
3
4
  user: AuthUser | undefined;
4
5
  scopes: string[];
5
6
  loading: boolean;
6
- error: Error | undefined;
7
+ error: AuthError | undefined;
7
8
  };
8
9
  export type UseAuthReturn = AuthState & {
9
10
  hasPlayServices: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"use-auth.d.ts","sourceRoot":"","sources":["../../../src/use-auth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,UAAU,EACX,MAAM,cAAc,CAAC;AAGtB,KAAK,SAAS,GAAG;IACf,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC3B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;CAC1B,CAAC;AA0BF,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG;IACtC,eAAe,EAAE,OAAO,CAAC;IACzB,KAAK,EAAE,CAAC,QAAQ,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzE,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,cAAc,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAClD,YAAY,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IACxC,aAAa,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC,CAAC;AAEF,wBAAgB,OAAO,IAAI,aAAa,CAyLvC"}
1
+ {"version":3,"file":"use-auth.d.ts","sourceRoot":"","sources":["../../../src/use-auth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,UAAU,EACX,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,KAAK,SAAS,GAAG;IACf,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC3B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,SAAS,GAAG,SAAS,CAAC;CAC9B,CAAC;AAYF,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG;IACtC,eAAe,EAAE,OAAO,CAAC;IACzB,KAAK,EAAE,CAAC,QAAQ,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzE,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,cAAc,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAClD,YAAY,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IACxC,aAAa,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC,CAAC;AAEF,wBAAgB,OAAO,IAAI,aAAa,CAgKvC"}
@@ -0,0 +1,16 @@
1
+ import type { AuthErrorCode } from "../Auth.nitro";
2
+ export declare function isAuthErrorCode(value: string): value is AuthErrorCode;
3
+ export declare function toAuthErrorCode(raw: string): AuthErrorCode;
4
+ /**
5
+ * Typed error thrown by all AuthService operations.
6
+ *
7
+ * - `code` — always a valid `AuthErrorCode`, safe to switch on
8
+ * - `underlyingMessage` — the raw platform message when it differs from `code`
9
+ */
10
+ export declare class AuthError extends Error {
11
+ readonly code: AuthErrorCode;
12
+ readonly underlyingMessage: string | undefined;
13
+ constructor(raw: unknown);
14
+ static from(e: unknown): AuthError;
15
+ }
16
+ //# sourceMappingURL=auth-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-error.d.ts","sourceRoot":"","sources":["../../../../src/utils/auth-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAkBnD,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,aAAa,CAErE;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAE1D;AAED;;;;;GAKG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC;gBAEnC,GAAG,EAAE,OAAO;IASxB,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,GAAG,SAAS;CAGnC"}
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../../src/utils/logger.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM;sBACC,OAAO,GAAG,IAAI;mBAGjB,OAAO,EAAE;oBAGR,OAAO,EAAE;qBAGR,OAAO,EAAE;qBAGT,OAAO,EAAE;CAG3B,CAAC"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../../src/utils/logger.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM;sBACC,OAAO,GAAG,IAAI;mBAGjB,OAAO,EAAE;oBAGR,OAAO,EAAE;qBAGR,OAAO,EAAE;qBAGT,OAAO,EAAE;CAG3B,CAAC"}
@@ -20,25 +20,30 @@
20
20
  namespace margelo::nitro::NitroAuth {
21
21
 
22
22
  int initialize(JavaVM* vm) {
23
+ return facebook::jni::initialize(vm, []() {
24
+ ::margelo::nitro::NitroAuth::registerAllNatives();
25
+ });
26
+ }
27
+
28
+
29
+
30
+ void registerAllNatives() {
23
31
  using namespace margelo::nitro;
24
32
  using namespace margelo::nitro::NitroAuth;
25
- using namespace facebook;
26
-
27
- return facebook::jni::initialize(vm, [] {
28
- // Register native JNI methods
29
-
30
-
31
- // Register Nitro Hybrid Objects
32
- HybridObjectRegistry::registerHybridObjectConstructor(
33
- "Auth",
34
- []() -> std::shared_ptr<HybridObject> {
35
- static_assert(std::is_default_constructible_v<HybridAuth>,
36
- "The HybridObject \"HybridAuth\" is not default-constructible! "
37
- "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
38
- return std::make_shared<HybridAuth>();
39
- }
40
- );
41
- });
33
+
34
+ // Register native JNI methods
35
+
36
+
37
+ // Register Nitro Hybrid Objects
38
+ HybridObjectRegistry::registerHybridObjectConstructor(
39
+ "Auth",
40
+ []() -> std::shared_ptr<HybridObject> {
41
+ static_assert(std::is_default_constructible_v<HybridAuth>,
42
+ "The HybridObject \"HybridAuth\" is not default-constructible! "
43
+ "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
44
+ return std::make_shared<HybridAuth>();
45
+ }
46
+ );
42
47
  }
43
48
 
44
49
  } // namespace margelo::nitro::NitroAuth
@@ -6,20 +6,29 @@
6
6
  ///
7
7
 
8
8
  #include <jni.h>
9
+ #include <functional>
9
10
  #include <NitroModules/NitroDefines.hpp>
10
11
 
11
12
  namespace margelo::nitro::NitroAuth {
12
13
 
14
+ [[deprecated("Use registerNatives() instead.")]]
15
+ int initialize(JavaVM* vm);
16
+
13
17
  /**
14
- * Initializes the native (C++) part of NitroAuth, and autolinks all Hybrid Objects.
15
- * Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`).
18
+ * Register the native (C++) part of NitroAuth, and autolinks all Hybrid Objects.
19
+ * Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`),
20
+ * inside a `facebook::jni::initialize(vm, ...)` call.
16
21
  * Example:
17
22
  * ```cpp (cpp-adapter.cpp)
18
23
  * JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
19
- * return margelo::nitro::NitroAuth::initialize(vm);
24
+ * return facebook::jni::initialize(vm, []() {
25
+ * // register all NitroAuth HybridObjects
26
+ * margelo::nitro::NitroAuth::registerNatives();
27
+ * // any other custom registrations go here.
28
+ * });
20
29
  * }
21
30
  * ```
22
31
  */
23
- int initialize(JavaVM* vm);
32
+ void registerAllNatives();
24
33
 
25
34
  } // namespace margelo::nitro::NitroAuth
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-auth",
3
- "version": "0.5.4",
3
+ "version": "0.5.6",
4
4
  "description": "High-performance authentication library for React Native with Google Sign-In, Apple Sign-In, and Microsoft Sign-In support, powered by Nitro Modules (JSI)",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",
@@ -35,9 +35,7 @@
35
35
  "codegen": "nitrogen --logLevel=\"debug\"",
36
36
  "lint": "eslint .",
37
37
  "typecheck": "tsc --noEmit",
38
- "format": "prettier --write .",
39
- "format:check": "prettier --check .",
40
- "test": "jest",
38
+ "test": "jest",
41
39
  "test:coverage": "jest --coverage",
42
40
  "test:cpp": "node scripts/test-cpp.js",
43
41
  "prepublishOnly": "bun run clean && bun run build",
@@ -81,21 +79,21 @@
81
79
  "access": "public"
82
80
  },
83
81
  "devDependencies": {
84
- "@expo/config-plugins": "^54.0.4",
85
- "@react-native/babel-preset": "^0.81.6",
82
+ "@expo/config-plugins": "^55.0.6",
83
+ "@react-native/babel-preset": "^0.83.0",
86
84
  "@testing-library/react": "^16.3.2",
87
85
  "@types/node": "^22.19.11",
88
86
  "jest-environment-jsdom": "^29.7.0",
89
- "react": "19.1.0",
90
- "react-native": "0.81.5",
91
- "react-native-nitro-modules": "^0.33.9",
87
+ "react": "19.2.0",
88
+ "react-native": "0.83.2",
89
+ "react-native-nitro-modules": "^0.35.0",
92
90
  "react-native-web": "^0.21.2",
93
91
  "typescript": "^5.9.3"
94
92
  },
95
93
  "peerDependencies": {
96
94
  "react": "*",
97
95
  "react-native": ">=0.75.0",
98
- "react-native-nitro-modules": ">=0.33.9"
96
+ "react-native-nitro-modules": ">=0.35.0"
99
97
  },
100
98
  "react-native-builder-bob": {
101
99
  "source": "src",
package/src/Auth.web.ts CHANGED
@@ -24,6 +24,7 @@ const WEB_STORAGE_MODES = new Set([
24
24
  STORAGE_MODE_MEMORY,
25
25
  ] as const);
26
26
  const inMemoryWebStorage = new Map<string, string>();
27
+ let _appleSdkLoadPromise: Promise<void> | undefined;
27
28
 
28
29
  type WebStorageDriver = {
29
30
  save(key: string, value: string): void;
@@ -152,6 +153,7 @@ const parseAuthWebExtraConfig = (value: unknown): AuthWebExtraConfig => {
152
153
 
153
154
  const getConfig = (): AuthWebExtraConfig => {
154
155
  try {
156
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
155
157
  const Constants = require("expo-constants").default;
156
158
  return parseAuthWebExtraConfig(Constants.expoConfig?.extra);
157
159
  } catch (error) {
@@ -175,7 +177,8 @@ class AuthWeb implements Auth {
175
177
  private _browserStorageResolved = false;
176
178
  private _browserStorageCache: Storage | undefined;
177
179
  private _refreshPromise: Promise<AuthTokens> | undefined;
178
- private _appleSdkLoadPromise: Promise<void> | undefined;
180
+ private _pendingGoogleNonce: string | undefined;
181
+ private _loginInFlight: boolean = false;
179
182
 
180
183
  constructor() {
181
184
  this._config = getConfig();
@@ -303,6 +306,7 @@ class AuthWeb implements Auth {
303
306
  const storage = this.getBrowserStorage();
304
307
  if (storage) {
305
308
  storage.removeItem(key);
309
+ return;
306
310
  }
307
311
  inMemoryWebStorage.delete(key);
308
312
  }
@@ -539,7 +543,7 @@ class AuthWeb implements Auth {
539
543
  const refreshToken = this.loadRefreshToken();
540
544
 
541
545
  if (!refreshToken) {
542
- throw new Error("No refresh token available");
546
+ throw new AuthWebError("refresh_failed", "No refresh token available");
543
547
  }
544
548
 
545
549
  const clientId = this._config.microsoftClientId;
@@ -645,13 +649,27 @@ class AuthWeb implements Auth {
645
649
 
646
650
  if (msg.includes("cancel") || msg.includes("popup_closed")) {
647
651
  mappedMsg = "cancelled";
652
+ } else if (msg.includes("access_denied")) {
653
+ mappedMsg = "cancelled";
648
654
  } else if (msg.includes("timeout")) {
649
655
  mappedMsg = "timeout";
650
656
  } else if (msg.includes("popup blocked")) {
651
657
  mappedMsg = "popup_blocked";
652
- } else if (msg.includes("network")) {
658
+ } else if (
659
+ msg.includes("network") ||
660
+ msg.includes("server_error") ||
661
+ msg.includes("temporarily_unavailable")
662
+ ) {
653
663
  mappedMsg = "network_error";
654
- } else if (msg.includes("client id") || msg.includes("config")) {
664
+ } else if (msg.includes("invalid_grant") || msg.includes("invalid_token")) {
665
+ mappedMsg = "refresh_failed";
666
+ } else if (
667
+ msg.includes("invalid_scope") ||
668
+ msg.includes("unauthorized_client") ||
669
+ msg.includes("invalid_client") ||
670
+ msg.includes("client id") ||
671
+ msg.includes("config")
672
+ ) {
655
673
  mappedMsg = "configuration_error";
656
674
  }
657
675
 
@@ -746,6 +764,24 @@ class AuthWeb implements Auth {
746
764
  private async loginGoogle(
747
765
  scopes: string[],
748
766
  loginHint?: string,
767
+ ): Promise<void> {
768
+ if (this._loginInFlight) {
769
+ throw new AuthWebError(
770
+ "cancelled",
771
+ "Another login is already in progress",
772
+ );
773
+ }
774
+ this._loginInFlight = true;
775
+ try {
776
+ await this._loginGoogleInner(scopes, loginHint);
777
+ } finally {
778
+ this._loginInFlight = false;
779
+ }
780
+ }
781
+
782
+ private async _loginGoogleInner(
783
+ scopes: string[],
784
+ loginHint?: string,
749
785
  ): Promise<void> {
750
786
  const clientId = this._config.googleWebClientId;
751
787
 
@@ -755,6 +791,8 @@ class AuthWeb implements Auth {
755
791
  );
756
792
  }
757
793
 
794
+ const nonce = crypto.randomUUID();
795
+ this._pendingGoogleNonce = nonce;
758
796
  return new Promise((resolve, reject) => {
759
797
  const redirectUri = window.location.origin;
760
798
  const authUrl = new URL("https://accounts.google.com/o/oauth2/v2/auth");
@@ -762,7 +800,7 @@ class AuthWeb implements Auth {
762
800
  authUrl.searchParams.set("redirect_uri", redirectUri);
763
801
  authUrl.searchParams.set("response_type", "id_token token code");
764
802
  authUrl.searchParams.set("scope", scopes.join(" "));
765
- authUrl.searchParams.set("nonce", crypto.randomUUID());
803
+ authUrl.searchParams.set("nonce", nonce);
766
804
  authUrl.searchParams.set("access_type", "offline");
767
805
  authUrl.searchParams.set("prompt", "consent");
768
806
 
@@ -798,6 +836,13 @@ class AuthWeb implements Auth {
798
836
  throw new Error("No id_token in response");
799
837
  }
800
838
 
839
+ const decoded = this.parseJwtPayload(idToken);
840
+ if (decoded["nonce"] !== this._pendingGoogleNonce) {
841
+ this._pendingGoogleNonce = undefined;
842
+ throw new Error("Nonce mismatch - possible replay attack");
843
+ }
844
+ this._pendingGoogleNonce = undefined;
845
+
801
846
  this._grantedScopes = scopes;
802
847
  this.saveValue(SCOPES_KEY, JSON.stringify(scopes));
803
848
 
@@ -842,6 +887,26 @@ class AuthWeb implements Auth {
842
887
  loginHint?: string,
843
888
  tenant?: string,
844
889
  prompt?: string,
890
+ ): Promise<void> {
891
+ if (this._loginInFlight) {
892
+ throw new AuthWebError(
893
+ "cancelled",
894
+ "Another login is already in progress",
895
+ );
896
+ }
897
+ this._loginInFlight = true;
898
+ try {
899
+ await this._loginMicrosoftInner(scopes, loginHint, tenant, prompt);
900
+ } finally {
901
+ this._loginInFlight = false;
902
+ }
903
+ }
904
+
905
+ private async _loginMicrosoftInner(
906
+ scopes: string[],
907
+ loginHint?: string,
908
+ tenant?: string,
909
+ prompt?: string,
845
910
  ): Promise<void> {
846
911
  const clientId = this._config.microsoftClientId;
847
912
 
@@ -1074,11 +1139,11 @@ class AuthWeb implements Auth {
1074
1139
  return;
1075
1140
  }
1076
1141
 
1077
- if (this._appleSdkLoadPromise) {
1078
- return this._appleSdkLoadPromise;
1142
+ if (_appleSdkLoadPromise) {
1143
+ return _appleSdkLoadPromise;
1079
1144
  }
1080
1145
 
1081
- this._appleSdkLoadPromise = new Promise<void>((resolve, reject) => {
1146
+ _appleSdkLoadPromise = new Promise<void>((resolve, reject) => {
1082
1147
  const scriptId = "nitro-auth-apple-sdk";
1083
1148
  const existingScript = document.getElementById(
1084
1149
  scriptId,
@@ -1102,7 +1167,7 @@ class AuthWeb implements Auth {
1102
1167
  existingScript.addEventListener(
1103
1168
  "error",
1104
1169
  () => {
1105
- this._appleSdkLoadPromise = undefined;
1170
+ _appleSdkLoadPromise = undefined;
1106
1171
  reject(new Error("Failed to load Apple SDK"));
1107
1172
  },
1108
1173
  { once: true },
@@ -1119,13 +1184,13 @@ class AuthWeb implements Auth {
1119
1184
  resolve();
1120
1185
  };
1121
1186
  script.onerror = () => {
1122
- this._appleSdkLoadPromise = undefined;
1187
+ _appleSdkLoadPromise = undefined;
1123
1188
  reject(new Error("Failed to load Apple SDK"));
1124
1189
  };
1125
1190
  document.head.appendChild(script);
1126
1191
  });
1127
1192
 
1128
- return this._appleSdkLoadPromise;
1193
+ return _appleSdkLoadPromise;
1129
1194
  }
1130
1195
 
1131
1196
  private async loginApple(): Promise<void> {
@@ -1199,6 +1264,7 @@ class AuthWeb implements Auth {
1199
1264
  logger.setEnabled(enabled);
1200
1265
  }
1201
1266
 
1267
+ /** @internal Reserved for future use — not part of the public API */
1202
1268
  setWebStorageAdapter(adapter: JSStorageAdapter | undefined): void {
1203
1269
  this._storageAdapter = adapter
1204
1270
  ? this.createWebStorageDriver(adapter)
package/src/global.d.ts CHANGED
@@ -1,16 +1,5 @@
1
1
  declare global {
2
2
  interface Window {
3
- google?: {
4
- accounts: {
5
- id: {
6
- initialize: (config: {
7
- client_id: string;
8
- callback: (response: { credential: string }) => void;
9
- }) => void;
10
- prompt: () => void;
11
- };
12
- };
13
- };
14
3
  AppleID?: {
15
4
  auth: {
16
5
  init: (config: {
package/src/index.ts CHANGED
@@ -2,3 +2,8 @@ export * from "./Auth.nitro";
2
2
  export * from "./ui/social-button";
3
3
  export { useAuth, type UseAuthReturn } from "./use-auth";
4
4
  export { AuthService } from "./service";
5
+ export {
6
+ AuthError,
7
+ isAuthErrorCode,
8
+ toAuthErrorCode,
9
+ } from "./utils/auth-error";
package/src/index.web.ts CHANGED
@@ -1,4 +1,9 @@
1
1
  export * from "./Auth.nitro";
2
2
  export * from "./ui/social-button.web";
3
- export * from "./use-auth";
3
+ export { useAuth, type UseAuthReturn } from "./use-auth";
4
4
  export { AuthService } from "./service.web";
5
+ export {
6
+ AuthError,
7
+ isAuthErrorCode,
8
+ toAuthErrorCode,
9
+ } from "./utils/auth-error";
package/src/service.ts CHANGED
@@ -6,8 +6,10 @@ import type {
6
6
  LoginOptions,
7
7
  AuthUser,
8
8
  } from "./Auth.nitro";
9
+ import { AuthError } from "./utils/auth-error";
9
10
 
10
11
  const nitroAuth = NitroModules.createHybridObject<Auth>("Auth");
12
+
11
13
  export const AuthService: Auth = {
12
14
  get name() {
13
15
  return nitroAuth.name;
@@ -26,23 +28,46 @@ export const AuthService: Auth = {
26
28
  },
27
29
 
28
30
  async login(provider: AuthProvider, options?: LoginOptions) {
29
- return nitroAuth.login(provider, options);
31
+ try {
32
+ await nitroAuth.login(provider, options);
33
+ return;
34
+ } catch (e) {
35
+ throw AuthError.from(e);
36
+ }
30
37
  },
31
38
 
32
39
  async requestScopes(scopes: string[]) {
33
- return nitroAuth.requestScopes(scopes);
40
+ try {
41
+ await nitroAuth.requestScopes(scopes);
42
+ return;
43
+ } catch (e) {
44
+ throw AuthError.from(e);
45
+ }
34
46
  },
35
47
 
36
48
  async revokeScopes(scopes: string[]) {
37
- return nitroAuth.revokeScopes(scopes);
49
+ try {
50
+ await nitroAuth.revokeScopes(scopes);
51
+ return;
52
+ } catch (e) {
53
+ throw AuthError.from(e);
54
+ }
38
55
  },
39
56
 
40
57
  async getAccessToken() {
41
- return nitroAuth.getAccessToken();
58
+ try {
59
+ return await nitroAuth.getAccessToken();
60
+ } catch (e) {
61
+ throw AuthError.from(e);
62
+ }
42
63
  },
43
64
 
44
65
  async refreshToken() {
45
- return nitroAuth.refreshToken();
66
+ try {
67
+ return await nitroAuth.refreshToken();
68
+ } catch (e) {
69
+ throw AuthError.from(e);
70
+ }
46
71
  },
47
72
 
48
73
  logout() {
@@ -50,13 +75,16 @@ export const AuthService: Auth = {
50
75
  },
51
76
 
52
77
  async silentRestore() {
53
- return nitroAuth.silentRestore();
78
+ try {
79
+ await nitroAuth.silentRestore();
80
+ return;
81
+ } catch (e) {
82
+ throw AuthError.from(e);
83
+ }
54
84
  },
55
85
 
56
86
  onAuthStateChanged(callback: (user: AuthUser | undefined) => void) {
57
- return nitroAuth.onAuthStateChanged((user) => {
58
- callback(user);
59
- });
87
+ return nitroAuth.onAuthStateChanged(callback);
60
88
  },
61
89
 
62
90
  onTokensRefreshed(callback: (tokens: AuthTokens) => void) {