auth0 / react-native-auth0

React Native toolkit for Auth0 API
https://auth0.com
MIT License
498 stars 210 forks source link

requireLocalAuthentication does not work when used via useAuth hook #880

Open botre opened 8 months ago

botre commented 8 months ago

Checklist

Description

The requireLocalAuthentication method exposed by the useAuth hook does not seem to work.

I have a hunch that it is because requireLocalAuthentication cannot be called after getCredentials, however a useEffect in Auth0Provider.tsx (line 79) calls getCredentials on mount. So this condition cannot be satisfied.

I can call the requireLocalAuthentication method exposed by the Auth0 directly as a workaround:

const configureLocalAuthentication = async () => {
  const auth0 = new Auth0({
    clientId,
    domain,
  })
  try {
    await auth0.credentialsManager.requireLocalAuthentication()
  } catch (error) {
    console.error(error)
  }
}

export const AuthManager = ({ children }: PropsWithChildren) => {
  useEffect(() => {
    configureLocalAuthentication()
  }, [])
  return (
    <Auth0Provider domain={domain} clientId={clientId} >
      {children}
    </Auth0Provider>
  )
}

I have tested this on a real device.

Reproduction

  1. Setup the provider
  2. Down the tree, call the requireLocalAuthentication exposed by the useAuth hook
    useEffect(() => {
    requireLocalAuthentication()
    }, [requireLocalAuthentication])
  3. Nothing happens.

Additional context

No response

react-native-auth0 version

3.1.0

React Native version

0.72.10

Expo version

49.0.23

Platform

iOS

Platform version(s)

17.4

brth31 commented 5 months ago

We are planning to address this issue along with other improvements in the next major release coming up this quarter. I'll share exact timelines by the mid of June.

thyming commented 5 months ago

any update on this @brth31 ?

desusai7 commented 2 months ago

Hi @botre , @thyming,

We've removed this API in v4 beta and made improvements around local authentication. Can you try it out once here and let us know how it goes ?

brth31 commented 1 week ago

@botre @thyming Could we close this issue if it is resolved in v4 beta?

thyming commented 4 days ago

sounds good to me 👍🏻

On Fri, Nov 15, 2024 at 12:19 AM Bharath Natarajan @.***> wrote:

@botre https://github.com/botre @thyming https://github.com/thyming Could we close this issue if it is resolved in v4 beta?

— Reply to this email directly, view it on GitHub https://github.com/auth0/react-native-auth0/issues/880#issuecomment-2477981867, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ5N2LKHTVTF36FB7DQYOL2AV76HAVCNFSM6AAAAABE6CVOJ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINZXHE4DCOBWG4 . You are receiving this because you were mentioned.Message ID: @.***>