@watever/auth-react-native
v1.0.0
Published
Official Watever OAuth authentication library for React Native applications
Maintainers
Readme
@watever/auth-react-native
Official Watever OAuth authentication library for React Native applications.
Installation
npm install @watever/auth-react-native
# or
yarn add @watever/auth-react-nativeAdditional Dependencies
npm install @react-native-async-storage/async-storage react-native-inappbrowser-reborn axios
# For Expo
expo install expo-random expo-cryptoiOS Setup
Add to ios/YourApp/Info.plist:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>watever</string>
</array>
</dict>
</array>Android Setup
Add to android/app/src/main/AndroidManifest.xml:
<activity
android:name=".MainActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="watever" />
</intent-filter>
</activity>Usage
1. Setup
import React from 'react';
import { WateverAuth, WateverAuthProvider } from '@watever/auth-react-native';
import App from './App';
const wateverAuth = new WateverAuth({
clientId: 'your_client_id',
clientSecret: 'your_client_secret',
redirectUri: 'watever://oauth/callback',
scopes: ['profile.read', 'merchant.read', 'merchant.write']
});
export default function Root() {
return (
<WateverAuthProvider client={wateverAuth}>
<App />
</WateverAuthProvider>
);
}2. Use in Components
import { useWateverAuth, WateverAuthButton } from '@watever/auth-react-native';
import { View, Text, Button } from 'react-native';
function MyScreen() {
const { user, isAuthenticated, logout } = useWateverAuth();
if (isAuthenticated) {
return (
<View>
<Text>Welcome {user.first_name}!</Text>
<Button title="Logout" onPress={logout} />
</View>
);
}
return (
<WateverAuthButton
onSuccess={() => console.log('Logged in!')}
onError={(error) => console.error(error)}
/>
);
}License
MIT © Watever
