Skip to content

Commit

Permalink
Accept authUrl rather than api_key and clientId
Browse files Browse the repository at this point in the history
  • Loading branch information
Shreyaschorge committed Apr 11, 2024
1 parent f255cd0 commit 30abac6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
2 changes: 1 addition & 1 deletion react-native-sign-in-with-neynar/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@neynar/react-native-signin",
"version": "0.2.8",
"version": "1.0.0",
"keywords": [
"react-native",
"neynar",
Expand Down
28 changes: 8 additions & 20 deletions react-native-sign-in-with-neynar/src/NeynarSigninButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ enum ButtonText {
}

interface IProps {
apiKey: string;
clientId: string;
authUrl: string;
successCallback: (data: ISuccessMessage) => void;
errorCallback?: (error: any) => void;
theme?: Theme;
Expand Down Expand Up @@ -76,8 +75,7 @@ interface IProps {
}

export const NeynarSigninButton = ({
apiKey,
clientId,
authUrl,
successCallback,
errorCallback = () => {},
theme = Theme.LIGHT,
Expand All @@ -99,7 +97,6 @@ export const NeynarSigninButton = ({
textStyles: customTextStyle,
}: IProps) => {
const [modalVisible, setModalVisible] = useState(false);
const [authUrl, setAuthUrl] = useState<string | null>(null);

const handleMessage = (event: WebViewMessageEvent) => {
const data = JSON.parse(event.nativeEvent.data);
Expand All @@ -108,20 +105,7 @@ export const NeynarSigninButton = ({
};

const handleOnPress = async () => {
try {
const response = await fetch(
`https://api.neynar.com/v2/farcaster/login/authorize?api_key=${apiKey}&response_type=code&client_id=${clientId}`
);

if (!response.ok) throw new Error("Something went wrong");

const json = await response.json();
setAuthUrl(json.authorization_url);
setModalVisible(true);
} catch (err) {
errorCallback(err);
setModalVisible(false);
}
setModalVisible(true);
};

const getLogo = () => {
Expand Down Expand Up @@ -217,7 +201,7 @@ export const NeynarSigninButton = ({
<Text style={styles.closeButtonText}>{"Close"}</Text>
</TouchableOpacity>
</View>
{authUrl && (
{authUrl ? (
<WebView
source={{
uri: authUrl,
Expand Down Expand Up @@ -250,6 +234,10 @@ export const NeynarSigninButton = ({
return false; // Prevent WebView from loading these URLs
}}
/>
) : (
<View>
<Text>{"authUrl is required"}</Text>
</View>
)}
</>
</SafeAreaView>
Expand Down

0 comments on commit 30abac6

Please sign in to comment.