Skip to content

Commit

Permalink
feat: update @logto/client (#31)
Browse files Browse the repository at this point in the history
* feat: update @logto/client

update @logto/client

* fix: fix lint

fix lint
  • Loading branch information
simeng-li authored Oct 8, 2024
1 parent 7687c31 commit 6776880
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 46 deletions.
2 changes: 0 additions & 2 deletions packages/rn-sample/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@ config.resolver.nodeModulesPaths = [
path.resolve(monorepoRoot, 'node_modules'),
];

config.resolver.unstable_enablePackageExports = true;

module.exports = config;
6 changes: 3 additions & 3 deletions packages/rn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publishConfig": {
"access": "public"
},
"version": "0.3.0",
"version": "0.4.0",
"type": "module",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down Expand Up @@ -49,8 +49,8 @@
},
"prettier": "@silverhand/eslint-config/.prettierrc",
"dependencies": {
"@logto/client": "2.4.0",
"@logto/js": "4.0.0",
"@logto/client": "2.8.1",
"@logto/js": "4.2.0",
"crypto-es": "^2.1.0",
"js-base64": "^3.7.7"
},
Expand Down
27 changes: 23 additions & 4 deletions packages/rn/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import {
Prompt,
StandardLogtoClient,
createRequester,
type SignInOptions,
type InteractionMode,
type LogtoConfig,
} from '@logto/client/shim';
} from '@logto/client';
import { decodeIdToken } from '@logto/js';
import * as WebBrowser from 'expo-web-browser';
import { Platform } from 'react-native';
Expand Down Expand Up @@ -66,7 +67,6 @@ export class LogtoClient extends StandardLogtoClient {
case 'sign-out': {
break;
}
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- just in case
default: {
throw new LogtoNativeClientError('navigation_purpose_not_supported');
}
Expand Down Expand Up @@ -103,6 +103,19 @@ export class LogtoClient extends StandardLogtoClient {
this.storage = storage;
}

/**
* Start the sign-in flow with the specified redirect URI. The URI must be registered in the
* Logto Console. It uses `WebBrowser.openAuthSessionAsync` to open the browser and start the
* sign-in flow.
*
* The user will be redirected to that URI after the sign-in flow is completed, and the client
* will handle the callback to exchange the authorization code for the tokens.
*
* @param options The options for the sign-in flow.
*
* @see {@link SignInOptions}
*/
override async signIn(options: SignInOptions): Promise<void>;
/**
* Start the sign-in flow with the specified redirect URI. The URI must be registered in the
* Logto Console. It uses `WebBrowser.openAuthSessionAsync` to open the browser and start the
Expand All @@ -117,8 +130,14 @@ export class LogtoClient extends StandardLogtoClient {
*
* @see {@link InteractionMode}
*/
override async signIn(redirectUri: string, interactionMode?: InteractionMode): Promise<void> {
await super.signIn(redirectUri, interactionMode);
override async signIn(redirectUri: string, interactionMode?: InteractionMode): Promise<void>;
override async signIn(
options: SignInOptions | string,
interactionMode?: InteractionMode
): Promise<void> {
await (typeof options === 'string'
? super.signIn(options, interactionMode)
: super.signIn(options));

if (this.authSessionResult?.type !== 'success') {
throw new LogtoNativeClientError('auth_session_failed');
Expand Down
13 changes: 10 additions & 3 deletions packages/rn/src/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type InteractionMode, type SignInOptions } from '@logto/client';
import { maybeCompleteAuthSession } from 'expo-web-browser';
import { useCallback, useContext, useEffect, useMemo } from 'react';

Expand All @@ -19,9 +20,15 @@ export const useLogto = () => {
maybeCompleteAuthSession();
}, []);

const signIn = useCallback(
async (redirectUri: string) => {
await client.signIn(redirectUri);
const signIn: {
(options: string, interactionMode?: InteractionMode): Promise<void>;
(options: SignInOptions): Promise<void>;
} = useCallback(
async (options: SignInOptions | string, interactionMode?: InteractionMode) => {
await (typeof options === 'string'
? client.signIn(options, interactionMode)
: client.signIn(options));

setIsAuthenticated(true);
},
[client, setIsAuthenticated]
Expand Down
4 changes: 2 additions & 2 deletions packages/rn/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type {
UserInfoResponse,
InteractionMode,
ClientAdapter,
} from '@logto/client/shim';
} from '@logto/client';

export {
createRequester,
Expand All @@ -22,7 +22,7 @@ export {
buildOrganizationUrn,
getOrganizationIdFromUrn,
PersistKey,
} from '@logto/client/shim';
} from '@logto/client';

export * from './client';
export * from './context';
Expand Down
2 changes: 1 addition & 1 deletion packages/rn/src/storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Storage, type StorageKey } from '@logto/client/shim';
import { type Storage, type StorageKey } from '@logto/client';
import AsyncStorage from '@react-native-async-storage/async-storage';
import type { Nullable } from '@silverhand/essentials';
import CryptoES from 'crypto-es';
Expand Down
Loading

0 comments on commit 6776880

Please sign in to comment.