-
Notifications
You must be signed in to change notification settings - Fork 6
/
SignInWithOAuth.tsx
38 lines (32 loc) · 1.13 KB
/
SignInWithOAuth.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { useOAuth } from "@clerk/clerk-expo";
import React from "react";
import { Button, View } from "react-native";
import { useWarmUpBrowser } from "../hooks/useWarmUpBrowser";
const SignInWithOAuth = () => {
useWarmUpBrowser();
const { startOAuthFlow } = useOAuth({ strategy: "oauth_discord" });
const handleSignInWithDiscordPress = React.useCallback(async () => {
try {
const { createdSessionId, signIn, signUp, setActive } =
await startOAuthFlow();
if (createdSessionId) {
setActive?.({ session: createdSessionId });
} else {
// Modify this code to use signIn or signUp to set this missing requirements you set in your dashboard.
throw new Error("There are unmet requirements, modifiy this else to handle them")
}
} catch (err) {
console.log(JSON.stringify(err, null, 2));
console.log("error signing in", err);
}
}, []);
return (
<View className="rounded-lg border-2 border-gray-500 p-4">
<Button
title="Sign in with Discord"
onPress={handleSignInWithDiscordPress}
/>
</View>
);
}
export default SignInWithOAuth;