AppProvider(props, context?): null | ReactElement<any, any>
Components nested within AppProvider
can access your App Services App and use the AppProvider
hooks.
All properties of AppConfiguration can be passed as props to AppProvider
.
To set up your App client, pass the App ID string to the id
prop of the AppProvider
. Wrap any components that need to access the App with AppProvider
.
import React from 'react';import {AppProvider} from '@realm/react';function AppWrapper() { return ( <View> <AppProvider id={APP_ID}> <MyApp /> </AppProvider> </View> );}
You can create multiple App client instances to connect to multiple Apps. All App client instances that share the same App ID use the same underlying connection.
Important Changing an App Config After Initializing the AppChanged in version realm@12.6.0
: baseUrl
is not cached
When you initialize the App client, the configuration is cached internally. Attempting to "close" and then re-open an App with a changed configuration within the same process has no effect. The client continues to use the cached configuration.
Starting with React Native SDK version 12.6.0, the baseUrl
in the AppConfiguration
is not cached. This means that you can change the baseUrl
and the App client will use the updated configuration. In earlier SDK versions, changes to the baseUrl
in a cached App configuration have no effect.
useAuth
has an authentication method for every App Services authentication provider.
Result of authentication hook operation. For example, result.operation
gives you the name of the current operation.
Enum values
state
. Can be "not-started", "pending", "success", "error".
operation
. For a list of all operation names, refer to the API documentation.
pending
. Can be true
or false
.
success
. Can be true
or false
.
error
. Error-based object or undefined.
logIn(credentials: Realm.Credentials): void
Parameters
credentials
. A Realm credential supplied by any supported Realm authentication.
Example
Logs in a user with any authentication mechanism supported by Realm. If called when a user is logged in, the current user switches to the new user. Usually, it's better to use the more specific login methods.
const {logIn, result} = useAuth();useEffect(() => logIn(Realm.Credentials.anonymous()), []);if(result.pending) { return (<LoadingSpinner/>)}if(result.error) { return (<ErrorComponent/>)}if(result.success) { return (<SuccessComponent/>)}
logInWithAnonymous(): void
Example
Log in with the anonymous authentication provider.
const {logInWithAnonymous, result} = useAuth();const performLogin = () => { logInWithAnonymous();};
logInWithApiKey(key: string): void
Parameters
key
. A string that is linked to an App Services user.
Example
Log in with an API key.
const {logInWithApiKey, result} = useAuth();const performLogin = () => {const key = getApiKey(); logInWithApiKey(key);};
logInWithEmailPassword(credentials: { email: string; password: string;}): void
Parameters
credentials
. An object with email
and password
fields.
Example
Log in with Email/Password.
const {logInWithEmailPassword, result} = useAuth();const [email, setEmail] = useState('');const [password, setPassword] = useState('');const performLogin = () => { logInWithEmailPassword({email, password});};
logInWithJWT(token: string): void
Parameters
credentials
. A string representation of a user's JWT.
Example
Log in with a JSON Web Token (JWT).
const {logInWithJWT, result} = useAuth();const performLogin = () => {const token = authorizeWithCustomerProvider(); logInWithJWT(token);};
logInWithGoogle(credentials: { idToken: string; } | { authCode: string; }): void;
Parameters
credentials
. An object with an idToken
or authCode
field that should contain the string token you get from Google Identity Services.
Example
Log in with Google.
const {logInWithGoogle, result} = useAuth();const performLogin = () => {const token = getGoogleToken(); logInWithGoogle({idToken: token});};
logInWithApple(idToken: string): void;
Parameters
idToken
. A string you get from the Apple SDK.
Example
Log in with Apple.
const {logInWithApple, result} = useAuth();const performLogin = () => {const token = getAppleToken(); logInWithApple(token);};
logInWithFacebook(accessToken: string): void;
Parameters
accessToken
. A string you get from the Facebook SDK.
Example
Log in with Facebook.
const {logInWithFacebook, result} = useAuth();const performLogin = () => {const token = getFacebookToken(); logInWithFacebook(token);};
logInWithFunction<PayloadType extends Record<string, unknown>>(payload: PayloadType): void;
Parameters
payload
. An object that contains user information you want to pass to the App Services function that processes log in requests.
Example
Log in with a custom function.
const {logInWithFunction, result} = useAuth();const performLogin = () => {const customPayload = getAuthParams(); logInWithFunction(customPayload);};
Example
Logs out the current user.
const {logOut, result} = useEmailPasswordAuth();const performLogout = () => { logOut();}
Result of authentication hook operation. For example, result.operation
gives you the name of the current operation.
Enum values
state
. Can be "not-started", "pending", "success", "error".
operation
. For a list of all operation names, refer to the API documentation.
pending
. Can be true
or false
.
success
. Can be true
or false
.
error
. Error-based object or undefined.
logIn(credentials: { email: string; password: string }): void;
Parameters
credentials
. An object that contains email
and password
properties.
Example
Logs a user in using an email and password. You could also call logIn(Realm.Credentials.emailPassword(email, password))
. Returns a Realm.User
instance of the logged-in user.
const {logIn, result} = useEmailPasswordAuth();const [email, setEmail] = useState('');const [password, setPassword] = useState('');const performLogin = () => { logIn({email, password});};if(result.pending) { return (<LoadingSpinner/>)}if(result.error) { return (<ErrorComponent/>)}if(result.success) { return (<SuccessComponent/>)}
Example
Logs out the current user.
const {logOut, result} = useEmailPasswordAuth();const performLogout = () => { logOut();}
register(args: { email: string; password: string }): void;
Parameters
args
. An object that contains email
and password
properties.
Example
Registers a new user. Requires a user email and password.
const {register, result} = useEmailPasswordAuth();const [email, setEmail] = useState('');const [password, setPassword] = useState('');const performRegister = () => { register({email, password});};
confirm(args: { token: string; tokenId: string }): void;
Parameters
args
. An object that contains token
and tokenId
properties.
Example
Confirms a user account. Requires a token
and tokenId
.
const {confirm, result} = useEmailPasswordAuth();const performConfirmation = () => { confirm({token, tokenId});};
resendConfirmationEmail(args: { email: string }): void;
Parameters
args
. An object that contains an email
property.
Example
Resends a confirmation email.
const {resendConfirmationEmail, result} = useEmailPasswordAuth();const [email, setEmail] = useState('');const performResendConfirmationEmail = () => { resendConfirmationEmail({email});};
retryCustomConfirmation(args: { email: string }): void;
Parameters
args
. An object that contains an email
property.
Example
Retries confirmation with a custom function.
const {retryCustomConfirmation, result} = useEmailPasswordAuth();const [email, setEmail] = useState('');const performRetryCustomConfirmation = () => { retryCustomConfirmation({email});};
sendResetPasswordEmail(args: { email: string }): void;
Parameters
args
. An object that contains an email
property.
Example
Sends a password reset email.
const {sendResetPasswordEmail, result} = useEmailPasswordAuth();const [email, setEmail] = useState('');const performSendResetPasswordEmail = () => { sendResetPasswordEmail({email});};
resetPassword(args: { token: string; tokenId: string; password: string }): void;
Parameters
args
. An object that contains token
, tokenId
, and password
properties.
Example
Resets a user's password.
const {resetPassword, result} = useEmailPasswordAuth();const [password, setPassword] = useState('');const performResetPassword = () => { resetPassword({token, tokenId, password});};
callResetPasswordFunction<Args extends unknown[] = []>( args: { email: string; password: string; }, ...restArgs: Args): void;
Parameters
args
. An object that contains email
and password
properties.
restArgs
. Additional arguments that you need to pass to your custom reset password function.
Example
Calls your App Services backend password reset function. Can pass arguments to the function as needed.
const {callResetPasswordFunction, result} = useEmailPasswordAuth();const [email, setEmail] = useState('');const [password, setPassword] = useState('');const performResetPassword = () => { callResetPasswordFunction({email, password}, "extraArg1", "extraArg2");};
useApp<FunctionsFactoryType, CustomDataType>(): Realm.App<FunctionsFactoryType, CustomDataType>
Example
The useApp()
hook provides access to a Realm.App instance.
import React from 'react';import {useApp} from '@realm/react';
function MyApp() { const app = useApp(); }
Returns
Realm.App
An instance of the current Realm.App
created by AppProvider
.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4