diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100644 index 00000000..c9272ed3 --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1 @@ +npm run prepush diff --git a/.shiprc b/.shiprc index 23070538..04893e42 100644 --- a/.shiprc +++ b/.shiprc @@ -1,6 +1,6 @@ { "files": { - "src/networking/telemetry.ts": [], + "src/core/utils/telemetry.ts": [], ".version": [] }, "postbump": "node scripts/jsdocs.js" diff --git a/EXAMPLES-WEB.md b/EXAMPLES-WEB.md new file mode 100644 index 00000000..24f7b7ed --- /dev/null +++ b/EXAMPLES-WEB.md @@ -0,0 +1,171 @@ +# React Native Auth0 for Web: Examples + +This guide provides usage examples specifically for developers targeting **React Native Web**. The web platform uses the underlying `@auth0/auth0-spa-js` library, and its features are aligned with browser security best practices. + +## 1. The Hooks-Based Approach (Recommended) + +This is the simplest and recommended way to integrate Auth0. The `Auth0Provider` handles all the complexity of the redirect flow automatically. + +### Step 1: Wrap Your App in the `Auth0Provider` + +In your main application entry point (e.g., `App.tsx`), wrap your application with the provider. + +```jsx +// src/App.tsx +import React from 'react'; +import { Auth0Provider } from 'react-native-auth0'; +import config from './auth0-configuration'; +import MainComponent from './MainComponent'; // Your main app UI + +const App = () => ( + + + +); + +export default App; +``` + +### Step 2: Use the `useAuth0` Hook in Your Components + +The `Auth0Provider` will automatically handle the redirect callback when your app loads. The `useAuth0` hook will then provide the authentication state. + +```jsx +// src/MainComponent.tsx +import React from 'react'; +import { useAuth0 } from 'react-native-auth0'; +import { View, Button, Text, ActivityIndicator } from 'react-native'; + +const MainComponent = () => { + const { authorize, clearSession, user, isLoading, error } = useAuth0(); + + const onLogin = async () => { + try { + // This triggers a redirect to the Auth0 Universal Login page. + await authorize({ scope: 'openid profile email' }); + } catch (e) { + console.error('Login error:', e); + } + }; + + const onLogout = async () => { + try { + await clearSession(); + } catch (e) { + console.error('Logout error:', e); + } + }; + + if (isLoading) { + return ( + + + + ); + } + + return ( + + {error && Error: {error.message}} + {user ? ( + <> + Welcome, {user.name}! +