Skip to content

Commit

Permalink
[lib] add identity register action
Browse files Browse the repository at this point in the history
Summary:
since this action is native-specific, i've created a new interface for native-only client methods.

Depends on D10440

Test Plan: successfully dispatched the action on native and registered a new account with staging identity service

Reviewers: ashoat, tomek, inka

Reviewed By: ashoat

Differential Revision: https://phab.comm.dev/D10454
  • Loading branch information
vdhanan committed Jan 17, 2024
1 parent 339b13b commit 011839e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/actions/user-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import type {
UpdateUserAvatarResponse,
} from '../types/avatar-types.js';
import type { RawEntryInfo, CalendarQuery } from '../types/entry-types.js';
import type { IdentityRegisterResult } from '../types/identity-service-types.js';
import type {
RawMessageInfo,
MessageTruncationStatuses,
Expand Down Expand Up @@ -372,6 +373,31 @@ function useKeyserverAuth(): (
);
}

const identityRegisterActionTypes = Object.freeze({
started: 'IDENTITY_REGISTER_STARTED',
success: 'IDENTITY_REGISTER_SUCCESS',
failed: 'IDENTITY_REGISTER_FAILED',
});
function useIdentityRegister(): (
username: string,
password: string,
) => Promise<IdentityRegisterResult> {
const client = React.useContext(IdentityClientContext);
const identityClient = client?.identityClient;
return React.useCallback(
(username, password) => {
if (!identityClient) {
throw new Error('Identity service client is not initialized');
}
if (!identityClient.registerUser) {
throw new Error('Register user method unimplemented');
}
return identityClient.registerUser(username, password);
},
[identityClient],
);
}

function mergeUserInfos(
...userInfoArrays: Array<$ReadOnlyArray<UserInfo>>
): UserInfo[] {
Expand Down Expand Up @@ -723,4 +749,6 @@ export {
useDeleteIdentityAccount,
keyserverAuthActionTypes,
useKeyserverAuth,
identityRegisterActionTypes,
useIdentityRegister,
};
10 changes: 10 additions & 0 deletions lib/types/identity-service-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export type OutboundKeyInfoResponse = {
export interface IdentityServiceClient {
+deleteUser: () => Promise<void>;
+getKeyserverKeys: string => Promise<?OutboundKeyInfoResponse>;
+registerUser?: (
username: string,
password: string,
) => Promise<IdentityRegisterResult>;
}

export type IdentityServiceAuthLayer = {
Expand All @@ -43,3 +47,9 @@ export type InboundKeyInfoResponse = {
+username?: ?string,
+walletAddress?: ?string,
};

export type IdentityRegisterResult = {
+userID: string,
+accessToken: string,
+username: string,
};

0 comments on commit 011839e

Please sign in to comment.