Skip to content

Commit 6776880

Browse files
authored
feat: update @logto/client (#31)
* feat: update @logto/client update @logto/client * fix: fix lint fix lint
1 parent 7687c31 commit 6776880

File tree

7 files changed

+106
-46
lines changed

7 files changed

+106
-46
lines changed

packages/rn-sample/metro.config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,4 @@ config.resolver.nodeModulesPaths = [
2121
path.resolve(monorepoRoot, 'node_modules'),
2222
];
2323

24-
config.resolver.unstable_enablePackageExports = true;
25-
2624
module.exports = config;

packages/rn/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publishConfig": {
44
"access": "public"
55
},
6-
"version": "0.3.0",
6+
"version": "0.4.0",
77
"type": "module",
88
"main": "./lib/index.js",
99
"types": "./lib/index.d.ts",
@@ -49,8 +49,8 @@
4949
},
5050
"prettier": "@silverhand/eslint-config/.prettierrc",
5151
"dependencies": {
52-
"@logto/client": "2.4.0",
53-
"@logto/js": "4.0.0",
52+
"@logto/client": "2.8.1",
53+
"@logto/js": "4.2.0",
5454
"crypto-es": "^2.1.0",
5555
"js-base64": "^3.7.7"
5656
},

packages/rn/src/client.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import {
33
Prompt,
44
StandardLogtoClient,
55
createRequester,
6+
type SignInOptions,
67
type InteractionMode,
78
type LogtoConfig,
8-
} from '@logto/client/shim';
9+
} from '@logto/client';
910
import { decodeIdToken } from '@logto/js';
1011
import * as WebBrowser from 'expo-web-browser';
1112
import { Platform } from 'react-native';
@@ -66,7 +67,6 @@ export class LogtoClient extends StandardLogtoClient {
6667
case 'sign-out': {
6768
break;
6869
}
69-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- just in case
7070
default: {
7171
throw new LogtoNativeClientError('navigation_purpose_not_supported');
7272
}
@@ -103,6 +103,19 @@ export class LogtoClient extends StandardLogtoClient {
103103
this.storage = storage;
104104
}
105105

106+
/**
107+
* Start the sign-in flow with the specified redirect URI. The URI must be registered in the
108+
* Logto Console. It uses `WebBrowser.openAuthSessionAsync` to open the browser and start the
109+
* sign-in flow.
110+
*
111+
* The user will be redirected to that URI after the sign-in flow is completed, and the client
112+
* will handle the callback to exchange the authorization code for the tokens.
113+
*
114+
* @param options The options for the sign-in flow.
115+
*
116+
* @see {@link SignInOptions}
117+
*/
118+
override async signIn(options: SignInOptions): Promise<void>;
106119
/**
107120
* Start the sign-in flow with the specified redirect URI. The URI must be registered in the
108121
* Logto Console. It uses `WebBrowser.openAuthSessionAsync` to open the browser and start the
@@ -117,8 +130,14 @@ export class LogtoClient extends StandardLogtoClient {
117130
*
118131
* @see {@link InteractionMode}
119132
*/
120-
override async signIn(redirectUri: string, interactionMode?: InteractionMode): Promise<void> {
121-
await super.signIn(redirectUri, interactionMode);
133+
override async signIn(redirectUri: string, interactionMode?: InteractionMode): Promise<void>;
134+
override async signIn(
135+
options: SignInOptions | string,
136+
interactionMode?: InteractionMode
137+
): Promise<void> {
138+
await (typeof options === 'string'
139+
? super.signIn(options, interactionMode)
140+
: super.signIn(options));
122141

123142
if (this.authSessionResult?.type !== 'success') {
124143
throw new LogtoNativeClientError('auth_session_failed');

packages/rn/src/hooks.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { type InteractionMode, type SignInOptions } from '@logto/client';
12
import { maybeCompleteAuthSession } from 'expo-web-browser';
23
import { useCallback, useContext, useEffect, useMemo } from 'react';
34

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

22-
const signIn = useCallback(
23-
async (redirectUri: string) => {
24-
await client.signIn(redirectUri);
23+
const signIn: {
24+
(options: string, interactionMode?: InteractionMode): Promise<void>;
25+
(options: SignInOptions): Promise<void>;
26+
} = useCallback(
27+
async (options: SignInOptions | string, interactionMode?: InteractionMode) => {
28+
await (typeof options === 'string'
29+
? client.signIn(options, interactionMode)
30+
: client.signIn(options));
31+
2532
setIsAuthenticated(true);
2633
},
2734
[client, setIsAuthenticated]

packages/rn/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export type {
66
UserInfoResponse,
77
InteractionMode,
88
ClientAdapter,
9-
} from '@logto/client/shim';
9+
} from '@logto/client';
1010

1111
export {
1212
createRequester,
@@ -22,7 +22,7 @@ export {
2222
buildOrganizationUrn,
2323
getOrganizationIdFromUrn,
2424
PersistKey,
25-
} from '@logto/client/shim';
25+
} from '@logto/client';
2626

2727
export * from './client';
2828
export * from './context';

packages/rn/src/storage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Storage, type StorageKey } from '@logto/client/shim';
1+
import { type Storage, type StorageKey } from '@logto/client';
22
import AsyncStorage from '@react-native-async-storage/async-storage';
33
import type { Nullable } from '@silverhand/essentials';
44
import CryptoES from 'crypto-es';

0 commit comments

Comments
 (0)