Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add oauth support to react native signer #1273

Merged
merged 27 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
54e714f
feat: add oauth popup logic
iykazrji Jan 9, 2025
3b017ca
feat: add basic oauth implementation for mobile
iykazrji Jan 10, 2025
fea47ce
feat: add basic oauth implementation for mobile
iykazrji Jan 10, 2025
59fd29a
Merge branch 'main' into iyk/add-oauth
iykazrji Jan 10, 2025
3163e18
fix: remove popup OAuth changes
iykazrji Jan 14, 2025
96517d0
feat: add auth completion using bundle
iykazrji Jan 14, 2025
26b19d6
Merge branch 'main' into iyk/add-oauth
iykazrji Jan 14, 2025
66f9b6c
fix: add error case when in-app browser is unavailable
iykazrji Jan 14, 2025
c130182
fix: remove errors file from rn-signer
iykazrji Jan 14, 2025
08a9fa5
fix: fix imports and linting
iykazrji Jan 15, 2025
7d87595
fix: remove react-native-webview package as it is currently unused
iykazrji Jan 15, 2025
3549ecf
fix: remove react-native-webview package as it is currently unused
iykazrji Jan 15, 2025
34e5851
feat: abstract signer to sepaeate module for import
iykazrji Jan 15, 2025
d646df4
Merge branch 'main' into iyk/add-oauth
iykazrji Jan 15, 2025
8e10d97
Merge branch 'main' into iyk/add-oauth
iykazrji Jan 15, 2025
f1754b1
feat: refactor getOauthProviderUrl() for reusability
iykazrji Jan 16, 2025
6150395
fix: remove unused function - getDeepLink()
iykazrji Jan 20, 2025
0aabec8
fix: fix oauthWithRedirect() method's return type
iykazrji Jan 20, 2025
e470782
feat: add inAppBrowserError class
iykazrji Jan 20, 2025
14d0914
feat: use protected instead of public for getOauthProviderUrl
iykazrji Jan 21, 2025
df035ed
Merge branch 'main' into iyk/add-oauth
iykazrji Jan 21, 2025
70693b3
Merge branch 'main' into iyk/add-oauth
iykazrji Jan 22, 2025
44969e4
Merge branch 'main' into iyk/add-oauth
iykazrji Jan 23, 2025
979d487
fix: remove getOauthNonce from exported signer members
iykazrji Jan 23, 2025
3928b92
fix: fix linting
iykazrji Jan 23, 2025
bc3a9a1
feat: add ts extension to signer index exports
iykazrji Jan 24, 2025
8e58124
fix: fix lintng
iykazrji Jan 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading