frappe-react-sdk 1.0.26 → 1.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -104,9 +104,9 @@ The hook uses `useSWR` under the hood to make the `get_current_user` API call -
104
104
  ```jsx
105
105
  export const MyAuthComponent = () => {
106
106
 
107
- const { currentUser, isValidating, login, logout, error, updateCurrentUser } = useFrappeAuth();
107
+ const { currentUser, isValidating, isLoading, login, logout, error, updateCurrentUser, getUserCookie } = useFrappeAuth();
108
108
 
109
- if (!currentUser && !error) return <div>loading...</div>
109
+ if (isLoading) return <div>loading...</div>
110
110
 
111
111
  // render user
112
112
  return <div>
@@ -118,9 +118,11 @@ export const MyAuthComponent = () => {
118
118
  </div>
119
119
  }
120
120
  ```
121
-
121
+ The hook will not make an API call if no cookie is found. If there is a cookie, it will call the `frappe.auth.get_logged_user` method.
122
122
  The hook will throw an error if the API call to `frappe.auth.get_logged_user` fails (network issue etc) or if the user is logged out (403 Forbidden). Handle errors accordingly and route the user to your login page if the error is because the user is not logged in.
123
123
 
124
+ The `getUserCookie` method can be used to reset the auth state if you encounter an authorization error in any other API call. This will then reset the `currentUser` to null.
125
+
124
126
  <br/>
125
127
 
126
128
  ## Database