useOAuth
Connect with third-party social accounts or authentication providers using OAuth flows.
Request
type Request = {
hook: 'useOAuth',
params: [options?: AuthHookOptions]
}
type AuthHookOptions = {
redirectTo?: string
logoutOnError?: boolean
recoverWalletAutomatically?: boolean
onSuccess?: (data: StoreCredentialsResult | InitOAuthReturnType) => void
onError?: (error: import("@openfort/react-native").OpenfortError) => void
onSettled?: (data: StoreCredentialsResult | InitOAuthReturnType | undefined | null, error: import("@openfort/react-native").OpenfortError | null) => void
throwOnError?: boolean
}
Response
type Response = UseOAuthReturn
type UseOAuthReturn = OAuthStatusFlags & {
initOAuth(options: InitializeOAuthOptions): Promise<InitOAuthReturnType>
linkOauth(options: InitializeOAuthOptions): Promise<InitOAuthReturnType>
storeCredentials(): void
}
type OAuthStatusFlags = {
isLoading: boolean
isError: boolean
isSuccess: boolean
error?: import("@openfort/react-native").OpenfortError | null
}
type InitOAuthReturnType = {
error?: import("@openfort/react-native").OpenfortError
user?: import("@openfort/openfort-js").AuthPlayerResponse
wallet?: import("@openfort/react-native").UserWallet
}
type StoreCredentialsResult = {
user?: import("@openfort/openfort-js").AuthPlayerResponse
wallet?: import("@openfort/react-native").UserWallet
error?: import("@openfort/react-native").OpenfortError
}
Example
import { OAuthProvider, useOAuth } from "@openfort/react-native"
function SocialLogin() {
const { initOAuth, linkOauth, storeCredentials, isLoading, isError, isSuccess, error } = useOAuth({
redirectTo: "https://app.example.com/auth/callback",
throwOnError: true,
onSuccess: () => {},
onError: () => {},
onSettled: () => {},
})
const loginWithGoogle = () => initOAuth({ provider: OAuthProvider.GOOGLE })
const linkWithApple = () => linkOauth({ provider: OAuthProvider.APPLE, isLegacyAppleIosBehaviorEnabled: true })
return null
}