Amazon Login module for React Native and Expo applications. Supports both iOS and Android.
- ✅ iOS Support (LoginWithAmazon SDK)
- ✅ Android Support (Login with Amazon SDK)
- ✅ Expo Config Plugin for easy setup
- ✅ TypeScript support
- ✅ Promise-based API
- ✅ Event listeners for login/logout
npm install react-native-amazon-login- Go to Amazon Developer Console
- Create a Security Profile
- Add iOS Settings with your bundle identifier
- Copy the API Key (JWT token)
- Go to Amazon Developer Console
- Add Android Settings
- Register your package name and app signature
- Copy the API Key
In your app.json:
{
"expo": {
"plugins": [
[
"react-native-amazon-login",
{
"amazonApiKey": "YOUR_AMAZON_API_KEY"
}
]
]
}
}The iOS SDK is included in the package. No additional steps needed!
- Download the Amazon Login SDK from Amazon Developer Portal
- Copy
login-with-amazon-sdk.aartonode_modules/react-native-amazon-login/android/libs/
See ANDROID_INSTALLATION.md for detailed instructions.
npx expo prebuild --clean
npx expo run:ios
npx expo run:androidimport {
login,
logout,
isLoggedIn,
getUserProfile,
} from "react-native-amazon-login";
// Login
const handleLogin = async () => {
try {
const userProfile = await login();
console.log("User:", userProfile);
// { userId, name, email, postalCode, accessToken }
} catch (error) {
console.error("Login failed:", error);
}
};
// Logout
const handleLogout = async () => {
try {
await logout();
console.log("Logged out");
} catch (error) {
console.error("Logout failed:", error);
}
};
// Check login status
const loggedIn = isLoggedIn();
// Get user profile
const profile = await getUserProfile();import {
addLoginSuccessListener,
addLoginFailureListener,
addLogoutListener,
} from "react-native-amazon-login";
// Listen for login success
const successSubscription = addLoginSuccessListener((userData) => {
console.log("Login successful:", userData);
});
// Listen for login failure
const failureSubscription = addLoginFailureListener((error) => {
console.error("Login failed:", error);
});
// Listen for logout
const logoutSubscription = addLogoutListener(() => {
console.log("User logged out");
});
// Clean up
successSubscription.remove();
failureSubscription.remove();
logoutSubscription.remove();import React, { useEffect, useState } from 'react';
import { View, Button, Text } from 'react-native';
import {
login,
logout,
addLoginSuccessListener,
addLoginFailureListener
} from 'react-native-amazon-login';
export default function App() {
const [user, setUser] = useState(null);
useEffect(() => {
const successSub = addLoginSuccessListener((userData) => {
setUser(userData);
});
const failureSub = addLoginFailureListener((error) => {
console.error('Login error:', error);
});
return () => {
successSub.remove();
failureSub.remove();
};
}, []);
const handleLogin = async () => {
try {
const userData = await login();
setUser(userData);
} catch (error) {
console.error('Login failed:', error);
}
};
const handleLogout = async () => {
try {
await logout();
setUser(null);
} catch (error) {
console.error('Logout failed:', error);
}
};
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
{user ? (
<>
<Text>Welcome, {user.name || user.email}!</Text>
<Button title="Logout" onPress={handleLogout} />
</>
) : (
<Button title="Login with Amazon" onPress={handleLogin} />
)}
</View>
);
}Initiates the Amazon login flow.
Returns: Promise that resolves with user profile data.
const user = await login();
// { userId, name, email, postalCode, accessToken }Signs out the current user.
await logout();Checks if a user is currently logged in.
const loggedIn = isLoggedIn();Fetches the current user's profile.
const profile = await getUserProfile();Listens for successful login events.
Listens for login failure events.
Listens for logout events.
interface AmazonUserProfile {
userId: string;
name?: string;
email?: string;
postalCode?: string;
accessToken?: string;
}
interface LoginFailureEventPayload {
type: string;
error: string;
userDidCancel: boolean;
code?: string;
domain?: string;
}"LoginWithAmazon not found"
- Run
npx expo prebuild --clean - Check that the plugin is configured in
app.json
"Invalid API Key"
- Verify your API key in Amazon Developer Console
- Check that your bundle identifier matches
"SDK not found"
- Make sure
login-with-amazon-sdk.aaris inandroid/libs/ - See ANDROID_INSTALLATION.md
"Invalid API Key"
- Verify your package name matches
- Check that your app signature is registered
- Make sure you're using the correct keystore
"Plugin not found"
- Run
npm installto ensure the package is installed - Run
npx expo prebuild --cleanto regenerate native code
- Expo SDK 50+
- iOS 15.1+
- Android API 24+
- React Native 0.70+
MIT
samsonroy samsonmaben@gmail.com