react-native-nitro-auth 0.1.0

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 (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +254 -0
  3. package/android/CMakeLists.txt +37 -0
  4. package/android/build.gradle +99 -0
  5. package/android/gradle.properties +4 -0
  6. package/android/src/main/AndroidManifest.xml +12 -0
  7. package/android/src/main/cpp/JniOnLoad.cpp +7 -0
  8. package/android/src/main/cpp/PlatformAuth+Android.cpp +293 -0
  9. package/android/src/main/java/com/auth/AuthAdapter.kt +286 -0
  10. package/android/src/main/java/com/auth/GoogleSignInActivity.kt +73 -0
  11. package/android/src/main/java/com/auth/NitroAuthModule.kt +19 -0
  12. package/android/src/main/java/com/auth/NitroAuthPackage.kt +16 -0
  13. package/app.plugin.js +64 -0
  14. package/cpp/AuthCache.cpp +105 -0
  15. package/cpp/AuthCache.hpp +20 -0
  16. package/cpp/HybridAuth.cpp +213 -0
  17. package/cpp/HybridAuth.hpp +47 -0
  18. package/cpp/JSONSerializer.hpp +57 -0
  19. package/cpp/PlatformAuth.hpp +25 -0
  20. package/ios/AuthAdapter.swift +200 -0
  21. package/ios/PlatformAuth+iOS.mm +119 -0
  22. package/lib/commonjs/Auth.nitro.js +6 -0
  23. package/lib/commonjs/Auth.nitro.js.map +1 -0
  24. package/lib/commonjs/Auth.web.js +256 -0
  25. package/lib/commonjs/Auth.web.js.map +1 -0
  26. package/lib/commonjs/global.d.js +6 -0
  27. package/lib/commonjs/global.d.js.map +1 -0
  28. package/lib/commonjs/index.js +52 -0
  29. package/lib/commonjs/index.js.map +1 -0
  30. package/lib/commonjs/index.web.js +52 -0
  31. package/lib/commonjs/index.web.js.map +1 -0
  32. package/lib/commonjs/service.js +9 -0
  33. package/lib/commonjs/service.js.map +1 -0
  34. package/lib/commonjs/service.web.js +13 -0
  35. package/lib/commonjs/service.web.js.map +1 -0
  36. package/lib/commonjs/ui/social-button.js +103 -0
  37. package/lib/commonjs/ui/social-button.js.map +1 -0
  38. package/lib/commonjs/ui/social-button.web.js +102 -0
  39. package/lib/commonjs/ui/social-button.web.js.map +1 -0
  40. package/lib/commonjs/use-auth.js +144 -0
  41. package/lib/commonjs/use-auth.js.map +1 -0
  42. package/lib/module/Auth.nitro.js +4 -0
  43. package/lib/module/Auth.nitro.js.map +1 -0
  44. package/lib/module/Auth.web.js +252 -0
  45. package/lib/module/Auth.web.js.map +1 -0
  46. package/lib/module/global.d.js +4 -0
  47. package/lib/module/global.d.js.map +1 -0
  48. package/lib/module/index.js +7 -0
  49. package/lib/module/index.js.map +1 -0
  50. package/lib/module/index.web.js +7 -0
  51. package/lib/module/index.web.js.map +1 -0
  52. package/lib/module/service.js +5 -0
  53. package/lib/module/service.js.map +1 -0
  54. package/lib/module/service.web.js +4 -0
  55. package/lib/module/service.web.js.map +1 -0
  56. package/lib/module/ui/social-button.js +97 -0
  57. package/lib/module/ui/social-button.js.map +1 -0
  58. package/lib/module/ui/social-button.web.js +96 -0
  59. package/lib/module/ui/social-button.web.js.map +1 -0
  60. package/lib/module/use-auth.js +140 -0
  61. package/lib/module/use-auth.js.map +1 -0
  62. package/lib/typescript/Auth.nitro.d.ts +38 -0
  63. package/lib/typescript/Auth.nitro.d.ts.map +1 -0
  64. package/lib/typescript/Auth.web.d.ts +32 -0
  65. package/lib/typescript/Auth.web.d.ts.map +1 -0
  66. package/lib/typescript/index.d.ts +5 -0
  67. package/lib/typescript/index.d.ts.map +1 -0
  68. package/lib/typescript/index.web.d.ts +5 -0
  69. package/lib/typescript/index.web.d.ts.map +1 -0
  70. package/lib/typescript/service.d.ts +3 -0
  71. package/lib/typescript/service.d.ts.map +1 -0
  72. package/lib/typescript/service.web.d.ts +2 -0
  73. package/lib/typescript/service.web.d.ts.map +1 -0
  74. package/lib/typescript/ui/social-button.d.ts +17 -0
  75. package/lib/typescript/ui/social-button.d.ts.map +1 -0
  76. package/lib/typescript/ui/social-button.web.d.ts +17 -0
  77. package/lib/typescript/ui/social-button.web.d.ts.map +1 -0
  78. package/lib/typescript/use-auth.d.ts +15 -0
  79. package/lib/typescript/use-auth.d.ts.map +1 -0
  80. package/nitro.json +15 -0
  81. package/nitrogen/generated/.gitattributes +1 -0
  82. package/nitrogen/generated/android/NitroAuth+autolinking.cmake +81 -0
  83. package/nitrogen/generated/android/NitroAuth+autolinking.gradle +27 -0
  84. package/nitrogen/generated/android/NitroAuthOnLoad.cpp +44 -0
  85. package/nitrogen/generated/android/NitroAuthOnLoad.hpp +25 -0
  86. package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/auth/NitroAuthOnLoad.kt +35 -0
  87. package/nitrogen/generated/ios/NitroAuth+autolinking.rb +60 -0
  88. package/nitrogen/generated/ios/NitroAuth-Swift-Cxx-Bridge.cpp +17 -0
  89. package/nitrogen/generated/ios/NitroAuth-Swift-Cxx-Bridge.hpp +27 -0
  90. package/nitrogen/generated/ios/NitroAuth-Swift-Cxx-Umbrella.hpp +38 -0
  91. package/nitrogen/generated/ios/NitroAuthAutolinking.mm +35 -0
  92. package/nitrogen/generated/ios/NitroAuthAutolinking.swift +12 -0
  93. package/nitrogen/generated/shared/c++/AuthProvider.hpp +76 -0
  94. package/nitrogen/generated/shared/c++/AuthTokens.hpp +84 -0
  95. package/nitrogen/generated/shared/c++/AuthUser.hpp +107 -0
  96. package/nitrogen/generated/shared/c++/HybridAuthSpec.cpp +30 -0
  97. package/nitrogen/generated/shared/c++/HybridAuthSpec.hpp +85 -0
  98. package/nitrogen/generated/shared/c++/LoginOptions.hpp +81 -0
  99. package/package.json +113 -0
  100. package/react-native-nitro-auth.podspec +40 -0
  101. package/src/Auth.nitro.ts +50 -0
  102. package/src/Auth.web.ts +310 -0
  103. package/src/global.d.ts +38 -0
  104. package/src/index.ts +4 -0
  105. package/src/index.web.ts +4 -0
  106. package/src/service.ts +4 -0
  107. package/src/service.web.ts +1 -0
  108. package/src/ui/social-button.tsx +129 -0
  109. package/src/ui/social-button.web.tsx +128 -0
  110. package/src/use-auth.ts +157 -0
@@ -0,0 +1,27 @@
1
+ ///
2
+ /// NitroAuth-Swift-Cxx-Bridge.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ // Forward declarations of C++ defined types
11
+
12
+
13
+ // Forward declarations of Swift defined types
14
+
15
+
16
+ // Include C++ defined types
17
+
18
+
19
+ /**
20
+ * Contains specialized versions of C++ templated types so they can be accessed from Swift,
21
+ * as well as helper functions to interact with those C++ types from Swift.
22
+ */
23
+ namespace margelo::nitro::NitroAuth::bridge::swift {
24
+
25
+
26
+
27
+ } // namespace margelo::nitro::NitroAuth::bridge::swift
@@ -0,0 +1,38 @@
1
+ ///
2
+ /// NitroAuth-Swift-Cxx-Umbrella.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ // Forward declarations of C++ defined types
11
+
12
+
13
+ // Include C++ defined types
14
+
15
+
16
+ // C++ helpers for Swift
17
+ #include "NitroAuth-Swift-Cxx-Bridge.hpp"
18
+
19
+ // Common C++ types used in Swift
20
+ #include <NitroModules/ArrayBufferHolder.hpp>
21
+ #include <NitroModules/AnyMapUtils.hpp>
22
+ #include <NitroModules/RuntimeError.hpp>
23
+ #include <NitroModules/DateToChronoDate.hpp>
24
+
25
+ // Forward declarations of Swift defined types
26
+
27
+
28
+ // Include Swift defined types
29
+ #if __has_include("NitroAuth-Swift.h")
30
+ // This header is generated by Xcode/Swift on every app build.
31
+ // If it cannot be found, make sure the Swift module's name (= podspec name) is actually "NitroAuth".
32
+ #include "NitroAuth-Swift.h"
33
+ // Same as above, but used when building with frameworks (`use_frameworks`)
34
+ #elif __has_include(<NitroAuth/NitroAuth-Swift.h>)
35
+ #include <NitroAuth/NitroAuth-Swift.h>
36
+ #else
37
+ #error NitroAuth's autogenerated Swift header cannot be found! Make sure the Swift module's name (= podspec name) is actually "NitroAuth", and try building the app first.
38
+ #endif
@@ -0,0 +1,35 @@
1
+ ///
2
+ /// NitroAuthAutolinking.mm
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #import <Foundation/Foundation.h>
9
+ #import <NitroModules/HybridObjectRegistry.hpp>
10
+
11
+ #import <type_traits>
12
+
13
+ #include "HybridAuth.hpp"
14
+
15
+ @interface NitroAuthAutolinking : NSObject
16
+ @end
17
+
18
+ @implementation NitroAuthAutolinking
19
+
20
+ + (void) load {
21
+ using namespace margelo::nitro;
22
+ using namespace margelo::nitro::NitroAuth;
23
+
24
+ HybridObjectRegistry::registerHybridObjectConstructor(
25
+ "Auth",
26
+ []() -> std::shared_ptr<HybridObject> {
27
+ static_assert(std::is_default_constructible_v<HybridAuth>,
28
+ "The HybridObject \"HybridAuth\" is not default-constructible! "
29
+ "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
30
+ return std::make_shared<HybridAuth>();
31
+ }
32
+ );
33
+ }
34
+
35
+ @end
@@ -0,0 +1,12 @@
1
+ ///
2
+ /// NitroAuthAutolinking.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ public final class NitroAuthAutolinking {
9
+ public typealias bridge = margelo.nitro.NitroAuth.bridge.swift
10
+
11
+
12
+ }
@@ -0,0 +1,76 @@
1
+ ///
2
+ /// AuthProvider.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/NitroHash.hpp>)
11
+ #include <NitroModules/NitroHash.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
16
+ #include <NitroModules/JSIConverter.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
21
+ #include <NitroModules/NitroDefines.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+ namespace margelo::nitro::NitroAuth {
27
+
28
+ /**
29
+ * An enum which can be represented as a JavaScript union (AuthProvider).
30
+ */
31
+ enum class AuthProvider {
32
+ GOOGLE SWIFT_NAME(google) = 0,
33
+ APPLE SWIFT_NAME(apple) = 1,
34
+ } CLOSED_ENUM;
35
+
36
+ } // namespace margelo::nitro::NitroAuth
37
+
38
+ namespace margelo::nitro {
39
+
40
+ // C++ AuthProvider <> JS AuthProvider (union)
41
+ template <>
42
+ struct JSIConverter<margelo::nitro::NitroAuth::AuthProvider> final {
43
+ static inline margelo::nitro::NitroAuth::AuthProvider fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
44
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
45
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
46
+ case hashString("google"): return margelo::nitro::NitroAuth::AuthProvider::GOOGLE;
47
+ case hashString("apple"): return margelo::nitro::NitroAuth::AuthProvider::APPLE;
48
+ default: [[unlikely]]
49
+ throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum AuthProvider - invalid value!");
50
+ }
51
+ }
52
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::NitroAuth::AuthProvider arg) {
53
+ switch (arg) {
54
+ case margelo::nitro::NitroAuth::AuthProvider::GOOGLE: return JSIConverter<std::string>::toJSI(runtime, "google");
55
+ case margelo::nitro::NitroAuth::AuthProvider::APPLE: return JSIConverter<std::string>::toJSI(runtime, "apple");
56
+ default: [[unlikely]]
57
+ throw std::invalid_argument("Cannot convert AuthProvider to JS - invalid value: "
58
+ + std::to_string(static_cast<int>(arg)) + "!");
59
+ }
60
+ }
61
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
62
+ if (!value.isString()) {
63
+ return false;
64
+ }
65
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
66
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
67
+ case hashString("google"):
68
+ case hashString("apple"):
69
+ return true;
70
+ default:
71
+ return false;
72
+ }
73
+ }
74
+ };
75
+
76
+ } // namespace margelo::nitro
@@ -0,0 +1,84 @@
1
+ ///
2
+ /// AuthTokens.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+
27
+
28
+ #include <string>
29
+ #include <optional>
30
+
31
+ namespace margelo::nitro::NitroAuth {
32
+
33
+ /**
34
+ * A struct which can be represented as a JavaScript object (AuthTokens).
35
+ */
36
+ struct AuthTokens {
37
+ public:
38
+ std::optional<std::string> accessToken SWIFT_PRIVATE;
39
+ std::optional<std::string> idToken SWIFT_PRIVATE;
40
+ std::optional<double> expirationTime SWIFT_PRIVATE;
41
+
42
+ public:
43
+ AuthTokens() = default;
44
+ explicit AuthTokens(std::optional<std::string> accessToken, std::optional<std::string> idToken, std::optional<double> expirationTime): accessToken(accessToken), idToken(idToken), expirationTime(expirationTime) {}
45
+ };
46
+
47
+ } // namespace margelo::nitro::NitroAuth
48
+
49
+ namespace margelo::nitro {
50
+
51
+ // C++ AuthTokens <> JS AuthTokens (object)
52
+ template <>
53
+ struct JSIConverter<margelo::nitro::NitroAuth::AuthTokens> final {
54
+ static inline margelo::nitro::NitroAuth::AuthTokens fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
55
+ jsi::Object obj = arg.asObject(runtime);
56
+ return margelo::nitro::NitroAuth::AuthTokens(
57
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "accessToken")),
58
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "idToken")),
59
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "expirationTime"))
60
+ );
61
+ }
62
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::NitroAuth::AuthTokens& arg) {
63
+ jsi::Object obj(runtime);
64
+ obj.setProperty(runtime, "accessToken", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.accessToken));
65
+ obj.setProperty(runtime, "idToken", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.idToken));
66
+ obj.setProperty(runtime, "expirationTime", JSIConverter<std::optional<double>>::toJSI(runtime, arg.expirationTime));
67
+ return obj;
68
+ }
69
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
70
+ if (!value.isObject()) {
71
+ return false;
72
+ }
73
+ jsi::Object obj = value.getObject(runtime);
74
+ if (!nitro::isPlainObject(runtime, obj)) {
75
+ return false;
76
+ }
77
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "accessToken"))) return false;
78
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "idToken"))) return false;
79
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "expirationTime"))) return false;
80
+ return true;
81
+ }
82
+ };
83
+
84
+ } // namespace margelo::nitro
@@ -0,0 +1,107 @@
1
+ ///
2
+ /// AuthUser.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+ // Forward declaration of `AuthProvider` to properly resolve imports.
27
+ namespace margelo::nitro::NitroAuth { enum class AuthProvider; }
28
+
29
+ #include "AuthProvider.hpp"
30
+ #include <string>
31
+ #include <optional>
32
+ #include <vector>
33
+
34
+ namespace margelo::nitro::NitroAuth {
35
+
36
+ /**
37
+ * A struct which can be represented as a JavaScript object (AuthUser).
38
+ */
39
+ struct AuthUser {
40
+ public:
41
+ AuthProvider provider SWIFT_PRIVATE;
42
+ std::optional<std::string> email SWIFT_PRIVATE;
43
+ std::optional<std::string> name SWIFT_PRIVATE;
44
+ std::optional<std::string> photo SWIFT_PRIVATE;
45
+ std::optional<std::string> idToken SWIFT_PRIVATE;
46
+ std::optional<std::string> accessToken SWIFT_PRIVATE;
47
+ std::optional<std::vector<std::string>> scopes SWIFT_PRIVATE;
48
+ std::optional<double> expirationTime SWIFT_PRIVATE;
49
+
50
+ public:
51
+ AuthUser() = default;
52
+ explicit AuthUser(AuthProvider provider, std::optional<std::string> email, std::optional<std::string> name, std::optional<std::string> photo, std::optional<std::string> idToken, std::optional<std::string> accessToken, std::optional<std::vector<std::string>> scopes, std::optional<double> expirationTime): provider(provider), email(email), name(name), photo(photo), idToken(idToken), accessToken(accessToken), scopes(scopes), expirationTime(expirationTime) {}
53
+ };
54
+
55
+ } // namespace margelo::nitro::NitroAuth
56
+
57
+ namespace margelo::nitro {
58
+
59
+ // C++ AuthUser <> JS AuthUser (object)
60
+ template <>
61
+ struct JSIConverter<margelo::nitro::NitroAuth::AuthUser> final {
62
+ static inline margelo::nitro::NitroAuth::AuthUser fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
63
+ jsi::Object obj = arg.asObject(runtime);
64
+ return margelo::nitro::NitroAuth::AuthUser(
65
+ JSIConverter<margelo::nitro::NitroAuth::AuthProvider>::fromJSI(runtime, obj.getProperty(runtime, "provider")),
66
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "email")),
67
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "name")),
68
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "photo")),
69
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "idToken")),
70
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "accessToken")),
71
+ JSIConverter<std::optional<std::vector<std::string>>>::fromJSI(runtime, obj.getProperty(runtime, "scopes")),
72
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "expirationTime"))
73
+ );
74
+ }
75
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::NitroAuth::AuthUser& arg) {
76
+ jsi::Object obj(runtime);
77
+ obj.setProperty(runtime, "provider", JSIConverter<margelo::nitro::NitroAuth::AuthProvider>::toJSI(runtime, arg.provider));
78
+ obj.setProperty(runtime, "email", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.email));
79
+ obj.setProperty(runtime, "name", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.name));
80
+ obj.setProperty(runtime, "photo", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.photo));
81
+ obj.setProperty(runtime, "idToken", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.idToken));
82
+ obj.setProperty(runtime, "accessToken", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.accessToken));
83
+ obj.setProperty(runtime, "scopes", JSIConverter<std::optional<std::vector<std::string>>>::toJSI(runtime, arg.scopes));
84
+ obj.setProperty(runtime, "expirationTime", JSIConverter<std::optional<double>>::toJSI(runtime, arg.expirationTime));
85
+ return obj;
86
+ }
87
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
88
+ if (!value.isObject()) {
89
+ return false;
90
+ }
91
+ jsi::Object obj = value.getObject(runtime);
92
+ if (!nitro::isPlainObject(runtime, obj)) {
93
+ return false;
94
+ }
95
+ if (!JSIConverter<margelo::nitro::NitroAuth::AuthProvider>::canConvert(runtime, obj.getProperty(runtime, "provider"))) return false;
96
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "email"))) return false;
97
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "name"))) return false;
98
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "photo"))) return false;
99
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "idToken"))) return false;
100
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "accessToken"))) return false;
101
+ if (!JSIConverter<std::optional<std::vector<std::string>>>::canConvert(runtime, obj.getProperty(runtime, "scopes"))) return false;
102
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "expirationTime"))) return false;
103
+ return true;
104
+ }
105
+ };
106
+
107
+ } // namespace margelo::nitro
@@ -0,0 +1,30 @@
1
+ ///
2
+ /// HybridAuthSpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridAuthSpec.hpp"
9
+
10
+ namespace margelo::nitro::NitroAuth {
11
+
12
+ void HybridAuthSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridGetter("currentUser", &HybridAuthSpec::getCurrentUser);
18
+ prototype.registerHybridGetter("grantedScopes", &HybridAuthSpec::getGrantedScopes);
19
+ prototype.registerHybridGetter("hasPlayServices", &HybridAuthSpec::getHasPlayServices);
20
+ prototype.registerHybridMethod("login", &HybridAuthSpec::login);
21
+ prototype.registerHybridMethod("requestScopes", &HybridAuthSpec::requestScopes);
22
+ prototype.registerHybridMethod("revokeScopes", &HybridAuthSpec::revokeScopes);
23
+ prototype.registerHybridMethod("getAccessToken", &HybridAuthSpec::getAccessToken);
24
+ prototype.registerHybridMethod("refreshToken", &HybridAuthSpec::refreshToken);
25
+ prototype.registerHybridMethod("logout", &HybridAuthSpec::logout);
26
+ prototype.registerHybridMethod("onAuthStateChanged", &HybridAuthSpec::onAuthStateChanged);
27
+ });
28
+ }
29
+
30
+ } // namespace margelo::nitro::NitroAuth
@@ -0,0 +1,85 @@
1
+ ///
2
+ /// HybridAuthSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+ // Forward declaration of `AuthUser` to properly resolve imports.
17
+ namespace margelo::nitro::NitroAuth { struct AuthUser; }
18
+ // Forward declaration of `AuthProvider` to properly resolve imports.
19
+ namespace margelo::nitro::NitroAuth { enum class AuthProvider; }
20
+ // Forward declaration of `LoginOptions` to properly resolve imports.
21
+ namespace margelo::nitro::NitroAuth { struct LoginOptions; }
22
+ // Forward declaration of `AuthTokens` to properly resolve imports.
23
+ namespace margelo::nitro::NitroAuth { struct AuthTokens; }
24
+
25
+ #include "AuthUser.hpp"
26
+ #include <optional>
27
+ #include <string>
28
+ #include <vector>
29
+ #include <NitroModules/Promise.hpp>
30
+ #include "AuthProvider.hpp"
31
+ #include "LoginOptions.hpp"
32
+ #include "AuthTokens.hpp"
33
+ #include <functional>
34
+
35
+ namespace margelo::nitro::NitroAuth {
36
+
37
+ using namespace margelo::nitro;
38
+
39
+ /**
40
+ * An abstract base class for `Auth`
41
+ * Inherit this class to create instances of `HybridAuthSpec` in C++.
42
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
43
+ * @example
44
+ * ```cpp
45
+ * class HybridAuth: public HybridAuthSpec {
46
+ * public:
47
+ * HybridAuth(...): HybridObject(TAG) { ... }
48
+ * // ...
49
+ * };
50
+ * ```
51
+ */
52
+ class HybridAuthSpec: public virtual HybridObject {
53
+ public:
54
+ // Constructor
55
+ explicit HybridAuthSpec(): HybridObject(TAG) { }
56
+
57
+ // Destructor
58
+ ~HybridAuthSpec() override = default;
59
+
60
+ public:
61
+ // Properties
62
+ virtual std::optional<AuthUser> getCurrentUser() = 0;
63
+ virtual std::vector<std::string> getGrantedScopes() = 0;
64
+ virtual bool getHasPlayServices() = 0;
65
+
66
+ public:
67
+ // Methods
68
+ virtual std::shared_ptr<Promise<void>> login(AuthProvider provider, const std::optional<LoginOptions>& options) = 0;
69
+ virtual std::shared_ptr<Promise<void>> requestScopes(const std::vector<std::string>& scopes) = 0;
70
+ virtual std::shared_ptr<Promise<void>> revokeScopes(const std::vector<std::string>& scopes) = 0;
71
+ virtual std::shared_ptr<Promise<std::optional<std::string>>> getAccessToken() = 0;
72
+ virtual std::shared_ptr<Promise<AuthTokens>> refreshToken() = 0;
73
+ virtual void logout() = 0;
74
+ virtual std::function<void()> onAuthStateChanged(const std::function<void(const std::optional<AuthUser>& /* user */)>& callback) = 0;
75
+
76
+ protected:
77
+ // Hybrid Setup
78
+ void loadHybridMethods() override;
79
+
80
+ protected:
81
+ // Tag for logging
82
+ static constexpr auto TAG = "Auth";
83
+ };
84
+
85
+ } // namespace margelo::nitro::NitroAuth
@@ -0,0 +1,81 @@
1
+ ///
2
+ /// LoginOptions.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+
27
+
28
+ #include <string>
29
+ #include <vector>
30
+ #include <optional>
31
+
32
+ namespace margelo::nitro::NitroAuth {
33
+
34
+ /**
35
+ * A struct which can be represented as a JavaScript object (LoginOptions).
36
+ */
37
+ struct LoginOptions {
38
+ public:
39
+ std::optional<std::vector<std::string>> scopes SWIFT_PRIVATE;
40
+ std::optional<std::string> loginHint SWIFT_PRIVATE;
41
+
42
+ public:
43
+ LoginOptions() = default;
44
+ explicit LoginOptions(std::optional<std::vector<std::string>> scopes, std::optional<std::string> loginHint): scopes(scopes), loginHint(loginHint) {}
45
+ };
46
+
47
+ } // namespace margelo::nitro::NitroAuth
48
+
49
+ namespace margelo::nitro {
50
+
51
+ // C++ LoginOptions <> JS LoginOptions (object)
52
+ template <>
53
+ struct JSIConverter<margelo::nitro::NitroAuth::LoginOptions> final {
54
+ static inline margelo::nitro::NitroAuth::LoginOptions fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
55
+ jsi::Object obj = arg.asObject(runtime);
56
+ return margelo::nitro::NitroAuth::LoginOptions(
57
+ JSIConverter<std::optional<std::vector<std::string>>>::fromJSI(runtime, obj.getProperty(runtime, "scopes")),
58
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "loginHint"))
59
+ );
60
+ }
61
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::NitroAuth::LoginOptions& arg) {
62
+ jsi::Object obj(runtime);
63
+ obj.setProperty(runtime, "scopes", JSIConverter<std::optional<std::vector<std::string>>>::toJSI(runtime, arg.scopes));
64
+ obj.setProperty(runtime, "loginHint", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.loginHint));
65
+ return obj;
66
+ }
67
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
68
+ if (!value.isObject()) {
69
+ return false;
70
+ }
71
+ jsi::Object obj = value.getObject(runtime);
72
+ if (!nitro::isPlainObject(runtime, obj)) {
73
+ return false;
74
+ }
75
+ if (!JSIConverter<std::optional<std::vector<std::string>>>::canConvert(runtime, obj.getProperty(runtime, "scopes"))) return false;
76
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "loginHint"))) return false;
77
+ return true;
78
+ }
79
+ };
80
+
81
+ } // namespace margelo::nitro