Skip to content

Commit

Permalink
Add ios support for passing action into passkey.signIn (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisfisher authored Apr 11, 2024
1 parent 07a59f4 commit 0aa6e8e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 14 deletions.
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ dependencies {

implementation "androidx.browser:browser:1.2.0"

implementation("com.authsignal:authsignal-push-android:0.2.8")
implementation("com.authsignal:authsignal-passkey-android:0.1.8")
implementation("com.authsignal:authsignal-push-android:0.2.9")
implementation("com.authsignal:authsignal-passkey-android:0.1.9")
}

if (isNewArchitectureEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ public void signUp(String token, String userName, String displayName, Promise pr
}

@ReactMethod
public void signIn(String token, Promise promise) {
public void signIn(String action, String token, Promise promise) {
if (authsignalPasskey != null) {
authsignalPasskey
.signInAsync(token)
.signInAsync(action, token)
.thenAcceptAsync(response -> {
if (response.getError() != null) {
promise.reject("signIn error", response.getError());
Expand Down
3 changes: 2 additions & 1 deletion ios/AuthsignalPasskeyModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ @interface RCT_EXTERN_MODULE(AuthsignalPasskeyModule, NSObject)
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(signIn:(NSString*)token
RCT_EXTERN_METHOD(signIn:(NSString*)action
withToken(NSString*)token
withAutofill:(BOOL)autofill
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
Expand Down
11 changes: 9 additions & 2 deletions ios/AuthsignalPasskeyModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,23 @@ class AuthsignalPasskeyModule: NSObject {
}
}

@objc func signIn(_ token: NSString?, withAutofill autofill: Bool, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
@objc func signIn(
_ action: NSString,
withToken token: NSString,
withAutofill autofill: Bool,
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock
) -> Void {
if (authsignal == nil) {
resolve(nil)
return
}

let actionStr = action as String?
let tokenStr = token as String?

Task.init {
let response = await authsignal!.signIn(token: tokenStr, autofill: autofill)
let response = await authsignal!.signIn(action: actionStr, token: tokenStr, autofill: autofill)

if (response.error != nil) {
reject("signIn error", response.error, nil)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-authsignal",
"version": "0.3.5",
"version": "0.3.6",
"description": "The official Authsignal React Native library.",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
2 changes: 1 addition & 1 deletion react-native-authsignal.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Pod::Spec.new do |s|
s.source_files = "ios/**/*.{h,m,mm,swift}"

s.dependency "React-Core"
s.dependency 'Authsignal', '0.2.2'
s.dependency 'Authsignal', '0.2.3'

# Don't install the dependencies when we run `pod install` in the old architecture.
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
Expand Down
17 changes: 12 additions & 5 deletions src/passkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface PasskeySignUpInput {
}

interface PasskeySignInInput {
action?: string;
token?: string;
autofill?: boolean;
}
Expand Down Expand Up @@ -72,9 +73,11 @@ export class AuthsignalPasskey {
}
}

async signIn({ token, autofill = false }: PasskeySignInInput = {}): Promise<
AuthsignalResponse<string>
> {
async signIn({
action,
token,
autofill = false,
}: PasskeySignInInput = {}): Promise<AuthsignalResponse<string>> {
await this.ensureModuleIsInitialized();

try {
Expand All @@ -87,13 +90,17 @@ export class AuthsignalPasskey {
}

if (Platform.OS === 'ios') {
const data = await AuthsignalPasskeyModule.signIn(token, autofill);
const data = await AuthsignalPasskeyModule.signIn(
action,
token,
autofill
);

autofillRequestPending = false;

return { data };
} else {
const data = await AuthsignalPasskeyModule.signIn(token);
const data = await AuthsignalPasskeyModule.signIn(action, token);

autofillRequestPending = false;

Expand Down

0 comments on commit 0aa6e8e

Please sign in to comment.