@eduzz/accounts-react-wrapper
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -0,1 +1,5 @@ | ||
## 1.1.0 (08 de Março de 2022) | ||
- Adicionando a feature: inicialização de interceptors para o axios. | ||
## 1.0.0 (02 de Março de 2022) | ||
@@ -2,0 +6,0 @@ |
{ | ||
"name": "@eduzz/accounts-react-wrapper", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"main": "./lib/cjs/index.js", | ||
@@ -37,2 +37,4 @@ "module": "./lib/esm/index.js", | ||
"jsonwebtoken": "^8", | ||
"react": "^16", | ||
"react-dom": "^16", | ||
"react-scripts": "4.0.3", | ||
@@ -42,5 +44,3 @@ "react-test-renderer": "^17.0.2", | ||
"typescript": "^4.4", | ||
"web-vitals": "^1.0.1", | ||
"react": "^16", | ||
"react-dom": "^16" | ||
"web-vitals": "^1.0.1" | ||
}, | ||
@@ -47,0 +47,0 @@ "peerDependencies": { |
@@ -210,2 +210,49 @@ # Eduzz Accounts React Wrapper | ||
### [4. Inicializar interceptors](#inicializar-interceptors) | ||
```jsx | ||
import { Apis } from 'web/services/api' | ||
import { useAuth } from '@eduzz/accounts-react-wrapper'; | ||
type ExapledBearerTokenDecoded = { | ||
name: string; | ||
email: string; | ||
} | ||
function App() { | ||
const { bearerTokenDecoded, loading, bearerToken, logout, interceptors } = useAuth<ExapledBearerTokenDecoded>(); | ||
function tryInitializeInterceptors() { | ||
if (bearerTokenDecoded?.exp) { | ||
interceptors?.axios.initialize({ | ||
interceptors: Apis.produtoFisicoApi.instance.interceptors, | ||
active: { // não obrigatório | ||
addBearerOnAllRequests: true, // default | ||
logoutWhenResponseIsUnauthorized: true, // default | ||
refreshWhenBearerTokenIsExpired: true, // default | ||
} | ||
}); | ||
} | ||
} | ||
useEffect(()=>{ | ||
tryInitializeInterceptors(); | ||
},[bearerToken]) | ||
return ( | ||
<div className='App'> | ||
<header className='App-header'> | ||
<div className="App"> | ||
<p>user name: {bearerTokenDecoded?.name}</p> | ||
<p>user email: {bearerTokenDecoded?.email}</p> | ||
<p>bearerToken: {bearerToken}</p> | ||
<p>loading: {loading}</p> | ||
<button onClick={logout}>Logout</button> | ||
</div> | ||
</header> | ||
</div> | ||
) | ||
} | ||
``` | ||
--- | ||
@@ -212,0 +259,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
266
8983
3
0
2