Skip to content

Commit 270ee19

Browse files
author
Kadi Kraman
committed
Update example app to handle empty refresh token from refresh, and no revoke when revocation endpoint is not defined
1 parent 0db2d0a commit 270ee19

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Example/App.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useCallback } from 'react';
1+
import React, { useState, useCallback, useMemo } from 'react';
22
import { UIManager, LayoutAnimation, Alert } from 'react-native';
33
import { authorize, refresh, revoke } from 'react-native-app-auth';
44
import { Page, Button, ButtonContainer, Form, FormLabel, FormValue, Heading } from './components';
@@ -59,7 +59,8 @@ export default () => {
5959

6060
setAuthState(current => ({
6161
...current,
62-
...newAuthState
62+
...newAuthState,
63+
refreshToken: newAuthState.refreshToken || current.refreshToken
6364
}))
6465

6566
} catch (error) {
@@ -84,6 +85,15 @@ export default () => {
8485
}
8586
}, [authState]);
8687

88+
const showRevoke = useMemo(() => {
89+
if (authState.accessToken) {
90+
if (config.issuer || config.serviceConfiguration.revocationEndpoint) {
91+
return true;
92+
}
93+
}
94+
return false;
95+
}, [authState]);
96+
8797
return (
8898
<Page>
8999
{!!authState.accessToken ? (
@@ -108,7 +118,7 @@ export default () => {
108118
{!!authState.refreshToken ? (
109119
<Button onPress={handleRefresh} text="Refresh" color="#24C2CB" />
110120
) : null}
111-
{!!authState.accessToken ? (
121+
{showRevoke ? (
112122
<Button onPress={handleRevoke} text="Revoke" color="#EF525B" />
113123
) : null}
114124
</ButtonContainer>

0 commit comments

Comments
 (0)