Skip to content

Commit

Permalink
Merge branch 'main' into caleb/otp-delay
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaleb4 authored Jan 24, 2025
2 parents 62bb975 + 61984bd commit a830e0b
Show file tree
Hide file tree
Showing 26 changed files with 566 additions and 204 deletions.
3 changes: 0 additions & 3 deletions account-kit/rn-signer/example/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
const path = require("path");
const { getDefaultConfig } = require("@react-native/metro-config");
const { getConfig } = require("react-native-builder-bob/metro-config");
const pkg = require("../package.json");

const rnSignerRoot = path.resolve(__dirname, "..");
const projectRoot = __dirname;
// handles the hoisted modules
Expand Down
1 change: 1 addition & 0 deletions account-kit/rn-signer/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"react-native": "0.76.5",
"react-native-config": "1.5.3",
"react-native-gesture-handler": "2.21.2",
"react-native-inappbrowser-reborn": "^3.7.0",
"react-native-mmkv": "3.1.0",
"react-native-safe-area-context": "4.14.0",
"react-native-screens": "4.2.0",
Expand Down
9 changes: 9 additions & 0 deletions account-kit/rn-signer/example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SafeAreaProvider } from "react-native-safe-area-context";

import OtpAuthScreen from "./screens/otp-auth";
import MagicLinkAuthScreen from "./screens/magic-link-auth";
import OauthScreen from "./screens/oauth";

const linking = {
enabled: "auto" as const /* Automatically generate paths for all screens */,
Expand All @@ -31,6 +32,14 @@ const RootStack = createBottomTabNavigator({
tabBarIcon: () => <Text>🔑</Text>,
},
},
OAuth: {
screen: OauthScreen,
linking: { path: "oauth" },
options: {
tabBarLabel: "Oauth",
tabBarIcon: () => <Text>🔐</Text>,
},
},
},
});

Expand Down
16 changes: 6 additions & 10 deletions account-kit/rn-signer/example/src/screens/magic-link-auth.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable import/extensions */
import { RNAlchemySigner } from "@account-kit/react-native-signer";
import type { User } from "@account-kit/signer";
import { useEffect, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import {
Linking,
StyleSheet,
Expand All @@ -10,13 +9,10 @@ import {
TouchableOpacity,
View,
} from "react-native";
import Config from "react-native-config";

export default function MagicLinkAuthScreen() {
const signer = RNAlchemySigner({
client: { connection: { apiKey: Config.API_KEY! } },
});
import signer from "../signer";

export default function MagicLinkAuthScreen() {
const [email, setEmail] = useState<string>("");
const [user, setUser] = useState<User | null>(null);

Expand All @@ -30,7 +26,7 @@ export default function MagicLinkAuthScreen() {
.catch(console.error);
};

const handleIncomingURL = (event: { url: string }) => {
const handleIncomingURL = useCallback((event: { url: string }) => {
const regex = /[?&]([^=#]+)=([^&#]*)/g;

let params: Record<string, string> = {};
Expand All @@ -49,7 +45,7 @@ export default function MagicLinkAuthScreen() {
handleUserAuth({
bundle: params.bundle ?? "",
});
};
}, []);

useEffect(() => {
// get the user if already logged in
Expand All @@ -61,7 +57,7 @@ export default function MagicLinkAuthScreen() {
const subscription = Linking.addEventListener("url", handleIncomingURL);

return () => subscription.remove();
}, []);
}, [handleIncomingURL]);

return (
<View style={styles.container}>
Expand Down
103 changes: 103 additions & 0 deletions account-kit/rn-signer/example/src/screens/oauth.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/* eslint-disable import/extensions */
import type { User } from "@account-kit/signer";
import { useEffect, useState } from "react";
import { View, Text, StyleSheet, TouchableOpacity } from "react-native";

import signer from "../signer";

export default function OAuthScreen() {
const [user, setUser] = useState<User | null>(null);

useEffect(() => {
// get the user if already logged in
signer.getAuthDetails().then(setUser);
signer.preparePopupOauth();
}, []);

return (
<View style={styles.container}>
{!user ? (
<>
<TouchableOpacity
style={styles.button}
onPress={() => {
signer
.authenticate({
type: "oauth",
mode: "redirect",
authProviderId: "google",
redirectUrl: "rn-signer-demo://oauth",
})
.then((user) => {
// Get user details after a successful authentication
setUser(user);
})
.catch(console.error);
}}
>
<Text style={styles.buttonText}>Sign in with OAuth</Text>
</TouchableOpacity>
</>
) : (
<>
<Text style={styles.userText}>
Currently logged in as: {user.email}
</Text>
<Text style={styles.userText}>OrgId: {user.orgId}</Text>
<Text style={styles.userText}>Address: {user.address}</Text>

<TouchableOpacity
style={styles.button}
onPress={() => signer.disconnect().then(() => setUser(null))}
>
<Text style={styles.buttonText}>Sign out</Text>
</TouchableOpacity>
</>
)}
</View>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center",
backgroundColor: "#FFFFF",
paddingHorizontal: 20,
},
textInput: {
width: "100%",
height: 40,
borderColor: "gray",
borderWidth: 1,
paddingHorizontal: 10,
backgroundColor: "rgba(0,0,0,0.05)",
marginTop: 20,
marginBottom: 10,
},
box: {
width: 60,
height: 60,
marginVertical: 20,
},
button: {
width: 200,
padding: 10,
height: 50,
backgroundColor: "rgb(147, 197, 253)",
borderRadius: 5,
alignItems: "center",
justifyContent: "center",
marginTop: 20,
},
buttonText: {
color: "white",
fontWeight: "bold",
textAlign: "center",
},
userText: {
marginBottom: 10,
fontSize: 18,
},
});
7 changes: 1 addition & 6 deletions account-kit/rn-signer/example/src/screens/otp-auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ import {
TouchableOpacity,
} from "react-native";

import Config from "react-native-config";
import { RNAlchemySigner } from "@account-kit/react-native-signer";

const signer = RNAlchemySigner({
client: { connection: { apiKey: Config.API_KEY! } },
});
import signer from "../signer";

export default function OTPAuthScreen() {
const [email, setEmail] = useState<string>("");
Expand Down
10 changes: 10 additions & 0 deletions account-kit/rn-signer/example/src/signer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { RNAlchemySigner } from "@account-kit/react-native-signer";
import Config from "react-native-config";

const signer = RNAlchemySigner({
client: {
connection: { apiKey: Config.API_KEY! },
},
});

export default signer;
2 changes: 2 additions & 0 deletions account-kit/rn-signer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"react": "18.3.1",
"react-native": "0.76.5",
"react-native-builder-bob": "^0.30.3",
"react-native-inappbrowser-reborn": "^3.7.0",
"react-native-mmkv": "^3.1.0",
"release-it": "^15.0.0",
"turbo": "^1.10.7",
Expand All @@ -93,6 +94,7 @@
"react-native": "*",
"react-native-config": "1.5.3",
"react-native-gesture-handler": "2.21.2",
"react-native-inappbrowser-reborn": "^3.7.0",
"react-native-mmkv": "^3.1.0"
},
"jest": {
Expand Down
Loading

0 comments on commit a830e0b

Please sign in to comment.