@@ -50,37 +50,41 @@ In this phase, we use OAuth2 with Hydra for authentication.
50
50
51
51
# ## Using the OAuth2 Provider
52
52
53
- Wrap your application with the ` OAuth2Provider ` and use the ` useOAuth ` hook within your components.
53
+ Use the ` useOAuth2 ` hook within your components.
54
54
55
55
` ` ` typescript
56
56
// src/App.tsx
57
57
import React from ' react' ;
58
- import { OAuth2Provider } from ' ./context/auth-context' ;
59
- import useOAuth from ' ./hooks/useOAuth' ;
60
- import { useAuthData } from ' @deriv-com/api-hooks' ;
58
+ import { useOAuth2 } from ' @deriv-com/auth-client' ;
61
59
62
- const App: React.FC = () => {
63
- const { logout } = useAuthData ();
64
- const oauthUrl = ' https://your-oauth-url.com' ;
60
+ const YourComponent = () => {
61
+ const [OAuth2EnabledApps, OAuth2EnabledAppsInitialised] = useGrowthbookGetFeatureValue< hydraBEApps>( {
62
+ featureFlag: ' hydra_be' ,
63
+ }) ;
65
64
66
- return (
67
- < OAuth2Provider logout={logout} oauthUrl={oauthUrl}>
68
- < YourComponent />
69
- < /OAuth2Provider>
70
- );
71
- };
65
+ const { logout } = useAuthData (); // Your custom hook or function to handle logout
72
66
73
- const YourComponent: React.FC = () => {
74
- const { oAuth2Logout } = useOAuth ();
67
+ const OAuth2GrowthBookConfig = {
68
+ OAuth2EnabledApps,
69
+ OAuth2EnabledAppsInitialised
70
+ };
71
+
72
+ const WSLogoutAndRedirect = async () => {
73
+ await logout ();
74
+ // Redirect or perform any additional actions here
75
+ };
76
+
77
+ const { OAuth2Logout } = useOAuth2(OAuth2GrowthBookConfig, WSLogoutAndRedirect);
75
78
76
79
return (
77
80
< div>
78
- < button onClick={oAuth2Logout }> Logout< /button>
81
+ < button onClick={OAuth2Logout }> Logout< /button>
79
82
< /div>
80
83
);
81
84
};
82
85
83
- export default App;
86
+ export default YourComponent;
87
+
84
88
` ` `
85
89
86
90
# # Phase 2: OIDC Public Client
0 commit comments