-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adee40f
commit f33faf8
Showing
3 changed files
with
417 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
.. list-table:: | ||
:header-rows: 1 | ||
:widths: 20 80 | ||
|
||
* - Method | ||
- Description and Example | ||
|
||
* - **result** | ||
|
||
- Result of authentication hook operation. ``result.operation`` gives you | ||
the name of the current operation. For a list of all operation names, | ||
refer to the :realm-react-sdk:`API documentation | ||
<enums/AuthOperationName.html>`. | ||
|
||
Possible result values: | ||
|
||
.. code:: typescript | ||
{ | ||
state, // "not-started", "pending", "success", "error" | ||
operation, // enum AuthOperationName | ||
pending, // true or false | ||
success, // true or false | ||
error // Error-based object or undefined | ||
} | ||
* - **logIn()** | ||
|
||
Props: *credentials: Realm.Credentials* | ||
Return: *void* | ||
- 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. | ||
|
||
.. code:: typescript | ||
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()** | ||
|
||
Props: none | ||
Return: *void* | ||
- Log in with the anonymous authentication provider. | ||
|
||
.. code:: typescript | ||
const {logInWithAnonymous, result} = useAuth(); | ||
const performLogin = () => { | ||
logInWithAnonymous(); | ||
}; | ||
* - **logInWithApiKey()** | ||
|
||
Props: *key: string* | ||
Return: *void* | ||
- Log in with an API key. | ||
|
||
.. code:: typescript | ||
const {logInWithApiKey, result} = useAuth(); | ||
const performLogin = () => { | ||
const key = getApiKey(); // user defined function | ||
logInWithApiKey(key); | ||
}; | ||
* - **logInWithEmailPassword()** | ||
|
||
Props: *credentials: {email: string; password: string;}* | ||
Return: *void* | ||
- Log in with Email/Password. | ||
|
||
.. code:: typescript | ||
const {logInWithEmailPassword, result} = useAuth(); | ||
const [email, setEmail] = useState(''); | ||
const [password, setPassword] = useState(''); | ||
const performLogin = () => { | ||
logInWithEmailPassword({email, password}); | ||
}; | ||
* - **logInWithJWT()** | ||
|
||
Props: *token: string* | ||
Return: *void* | ||
- Log in with a JSON Web Token (JWT). | ||
|
||
.. code:: typescript | ||
const {logInWithJWT, result} = useAuth(); | ||
const performLogin = () => { | ||
const token = authorizeWithCustomerProvider(); // user defined function | ||
logInWithJWT(token); | ||
}; | ||
* - **logInWithGoogle()** | ||
|
||
Props: *credentials: {idToken: string;} | {authCode: string;}* | ||
Return: *void* | ||
- Log in with Google. | ||
|
||
.. code:: typescript | ||
const {logInWithGoogle, result} = useAuth(); | ||
const performLogin = () => { | ||
const token = getGoogleToken(); // user defined function | ||
logInWithGoogle({idToken: token}); | ||
}; | ||
* - **logInWithApple()** | ||
|
||
Props: *credentials: idToken: string;* | ||
Return: *void* | ||
- Log in with Apple. | ||
|
||
.. code:: typescript | ||
const {logInWithApple, result} = useAuth(); | ||
const performLogin = () => { | ||
const token = getAppleToken(); // user defined function | ||
logInWithApple(token); | ||
}; | ||
* - **logInWithFacebook()** | ||
|
||
Props: *credentials: accessToken: string;* | ||
Return: *void* | ||
- Log in with Facebook. | ||
|
||
.. code:: typescript | ||
const {logInWithFacebook, result} = useAuth(); | ||
const performLogin = () => { | ||
const token = getFacebookToken(); // user defined function | ||
logInWithFacebook(token); | ||
}; | ||
* - **logInWithFunction()** | ||
|
||
Props: *payload: PayloadType* | ||
Return: *void* | ||
- Log in with a custom function. | ||
|
||
.. code:: typescript | ||
const {logInWithFunction, result} = useAuth(); | ||
const performLogin = () => { | ||
const customPayload = getAuthParams(); // user defined arguments | ||
logInWithFunction(customPayload); | ||
}; | ||
* - **logOut()** | ||
|
||
Props: none | ||
Return: *void* | ||
- Logs out the current user. | ||
|
||
.. code:: typescript | ||
const {logOut, result} = useEmailPasswordAuth(); | ||
const performLogout = () => { | ||
logOut(); | ||
} |
Oops, something went wrong.