Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Expose exchangeNativeSocial to useAuth0 hook
  • Loading branch information
mnemitz committed Dec 18, 2024
commit 7eef86551f7afe834bf4218ca1eaf163b08bd9ad
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-native-auth0",
"name": "@speechmatics/react-native-auth0",
"title": "React Native Auth0",
"version": "4.0.0",
"version": "4.0.1-sm.0",
"description": "React Native toolkit for Auth0 API",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
9 changes: 9 additions & 0 deletions src/hooks/auth0-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
WebAuthorizeParameters,
PasswordlessWithSMSOptions,
ClearSessionOptions,
ExchangeNativeSocialOptions,
} from '../types';

export interface Auth0ContextInterface<TUser extends User = User>
Expand Down Expand Up @@ -71,6 +72,13 @@ export interface Auth0ContextInterface<TUser extends User = User>
authorizeWithRecoveryCode: (
parameters: LoginWithRecoveryCodeOptions
) => Promise<Credentials | undefined>;
/**
* Exchange an external token obtained via a native social authentication solution for the user's tokens.
* See {@link Auth#exchangeNativeSocial}
*/
exchangeNativeSocial: (
parameters: ExchangeNativeSocialOptions
) => Promise<Credentials | undefined>;
/**
* Whether the SDK currently holds valid, unexpired credentials.
* @param minTtl The minimum time in seconds that the access token should last before expiration
Expand Down Expand Up @@ -139,6 +147,7 @@ const initialContext = {
authorizeWithOOB: stub,
authorizeWithOTP: stub,
authorizeWithRecoveryCode: stub,
exchangeNativeSocial: stub,
hasValidCredentials: stub,
clearSession: stub,
getCredentials: stub,
Expand Down
20 changes: 20 additions & 0 deletions src/hooks/auth0-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ClearSessionOptions,
ClearSessionParameters,
Credentials,
ExchangeNativeSocialOptions,
LoginWithEmailOptions,
LoginWithOOBOptions,
LoginWithOTPOptions,
Expand Down Expand Up @@ -301,6 +302,23 @@ const Auth0Provider = ({
[client]
);

const exchangeNativeSocial = useCallback(
async (parameters: ExchangeNativeSocialOptions) => {
try {
const credentials = await client.auth.exchangeNativeSocial(parameters);
const user = getIdTokenProfileClaims(credentials.idToken);

await client.credentialsManager.saveCredentials(credentials);
dispatch({ type: 'LOGIN_COMPLETE', user });
return credentials;
} catch (error) {
dispatch({ type: 'ERROR', error });
return;
}
},
[client]
);

const hasValidCredentials = useCallback(
async (minTtl: number = 0) => {
return await client.credentialsManager.hasValidCredentials(minTtl);
Expand Down Expand Up @@ -330,6 +348,7 @@ const Auth0Provider = ({
authorizeWithOOB,
authorizeWithOTP,
authorizeWithRecoveryCode,
exchangeNativeSocial,
hasValidCredentials,
clearSession,
getCredentials,
Expand All @@ -346,6 +365,7 @@ const Auth0Provider = ({
authorizeWithOOB,
authorizeWithOTP,
authorizeWithRecoveryCode,
exchangeNativeSocial,
hasValidCredentials,
clearSession,
getCredentials,
Expand Down