Skip to content

Commit 398bb9d

Browse files
committed
improved readme + renamed stripe functions
1 parent 6112c2a commit 398bb9d

File tree

4 files changed

+27
-36
lines changed

4 files changed

+27
-36
lines changed

README.md

+11-16
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,15 @@ If using Create React App, set :
3939

4040
in `.env.local` file to make the environment variable accessible on `process.env`.
4141

42-
```
43-
//.env.local
42+
```.env
43+
#.env.local
4444
4545
REACT_APP_EASYAUTH_APP_URL=https://<your_subdomain>.app.easyauth.io
4646
REACT_APP_EASYAUTH_CLIENT_ID=<client_id>
4747
REACT_APP_EASYAUTH_REDIRECT_URL=<redirect_uri such as http://127.0.0.1:3000>
4848
4949
```
5050

51-
52-
5351
Example App:
5452

5553
```jsx
@@ -70,6 +68,7 @@ root.render(
7068
);
7169
```
7270

71+
_User can also pass authority,clientId,redirectUri explicitly as a prop in EasauthProvider component._
7372

7473
```jsx
7574
//App.js
@@ -123,19 +122,15 @@ function App() {
123122
export default App;
124123
```
125124
125+
```jsx
126+
<EasyauthProvider
127+
authority={process.env.REACT_APP_EASYAUTH_APP_URL}
128+
clientId={process.env.REACT_APP_EASYAUTH_CLIENT_ID}
129+
redirectUri={process.env.REACT_APP_EASYAUTH_REDIRECT_URL}
130+
>
131+
<App />
132+
</EasyauthProvider>
126133
```
127-
User can also pass authority,clientId,redirectUri explicitly as a prop in EasauthProvider component
128-
for example,
129-
...
130-
<EasyauthProvider
131-
authority={process.env.REACT_APP_EASYAUTH_APP_URL}
132-
clientId={process.env.REACT_APP_EASYAUTH_CLIENT_ID}
133-
redirectUri={process.env.REACT_APP_EASYAUTH_REDIRECT_URL}
134-
>
135-
<App />
136-
</EasyauthProvider>
137-
138-
```
139134
140135
_For further details and examples, please refer to our [Documentation](https://easyauth.io/docs/quickstart/react/)._
141136

src/api/api.js

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const BASE_URL = process.env.REACT_APP_EASYAUTH_APP_URL + '/tenantbackend';
22

3-
let token;
3+
44
const tokenLocalStorage = () => {
55
let result;
66
const keys = Object.keys(localStorage);
@@ -10,11 +10,8 @@ const tokenLocalStorage = () => {
1010
}
1111
});
1212
const value = localStorage.getItem(result);
13-
token = JSON.parse(value)?.id_token;
13+
return JSON.parse(value)?.id_token;
1414
};
15-
if (!token) {
16-
tokenLocalStorage();
17-
}
1815

1916
const commonAPICall = async (
2017
PATH,
@@ -25,14 +22,13 @@ const commonAPICall = async (
2522
'Content-Type': 'application/json',
2623
},
2724
) => {
28-
tokenLocalStorage();
2925
const FULLPATH = BASE_URL + PATH;
3026
const response = await fetch(FULLPATH, {
3127
method: METHOD,
3228
body: BODY,
3329
headers: {
3430
...headers,
35-
Authorization: `Bearer ${token}`,
31+
Authorization: `Bearer ${tokenLocalStorage()}`,
3632
},
3733
});
3834

@@ -60,15 +56,15 @@ const getProfile = async () => {
6056
const response = await getAPI('/api/profile');
6157
return response;
6258
};
63-
const getCreatePortalSessionUrl = async () => {
59+
const getStripeCreatePortalSessionUrl = async () => {
6460
const response = await getAPI('/api/stripe/create-portal-session');
6561
return response;
6662
};
67-
const getCheckoutUrl = async (priceId) => {
63+
const getStripeCheckoutUrl = async (priceId) => {
6864
const response = await getAPI(`/api/stripe/checkout/${priceId}`);
6965
return response;
7066
};
71-
const getSubscriptions = async () => {
67+
const getStripeSubscriptions = async () => {
7268
const response = await getAPI('/api/stripe/subscriptions');
7369
return response;
7470
};
@@ -78,7 +74,7 @@ export {
7874
getAPI,
7975
postAPI,
8076
getProfile,
81-
getCreatePortalSessionUrl,
82-
getCheckoutUrl,
83-
getSubscriptions,
77+
getStripeCreatePortalSessionUrl,
78+
getStripeCheckoutUrl,
79+
getStripeSubscriptions,
8480
};

src/hooks/useStripe/useStripe.jsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import {
2-
getCheckoutUrl,
3-
getCreatePortalSessionUrl,
4-
getSubscriptions,
2+
getStripeCheckoutUrl,
3+
getStripeCreatePortalSessionUrl,
4+
getStripeSubscriptions,
55
} from '../../api/api.js';
66

77
export const useStripe = () => {
88
const createPortalSession = async () => {
9-
const response = await getCreatePortalSessionUrl();
9+
const response = await getStripeCreatePortalSessionUrl();
1010
return response.data.url;
1111
};
1212

1313
const checkout = async (priceId) => {
14-
const response = await getCheckoutUrl(priceId);
14+
const response = await getStripeCheckoutUrl(priceId);
1515
return response.data.url;
1616
};
1717
const subscriptions = async () => {
18-
const response = await getSubscriptions();
18+
const response = await getStripeSubscriptions();
1919
return response.data;
2020
};
2121
return {createPortalSession, checkout, subscriptions};

src/hooks/useUser/useUser.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const useUser = () => {
1212
};
1313

1414
fetchUser();
15-
}, []);
15+
}, [auth]);
1616

1717
return {
1818
isAuthenticated: auth.isAuthenticated,

0 commit comments

Comments
 (0)