Skip to content

Commit

Permalink
Merge pull request #22 from thisyahlen-deriv/thisyahlen/auth-provider…
Browse files Browse the repository at this point in the history
…-logout

chore: add logout ws call in context
  • Loading branch information
thisyahlen-deriv authored Sep 12, 2024
2 parents 5d185e5 + 6fad510 commit 686c48b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/context/auth-context.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { createContext, useEffect, useCallback } from 'react';
import { getOAuthLogoutUrl, getOAuthOrigin } from '../constants/';
import { useAuthData } from '@deriv-com/api-hooks';

type MessageEvent = {
data: 'logout_complete' | 'logout_error';
Expand All @@ -12,13 +13,14 @@ type OAuth2ContextValue = {

type OAuth2ProviderProps = {
children: React.ReactNode;
logout: () => Promise<void>;
oauthUrl: string;
};

export const OAuth2Context = createContext<OAuth2ContextValue | undefined>(undefined);

export const OAuth2Provider: React.FC<OAuth2ProviderProps> = ({ children, logout, oauthUrl }) => {
export const OAuth2Provider: React.FC<OAuth2ProviderProps> = ({ children, oauthUrl }) => {
const { logout } = useAuthData();

const WSLogoutAndRedirect = useCallback(async () => {
await logout();
window.open(oauthUrl, '_self');
Expand Down
8 changes: 7 additions & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import App from './App';
import './index.css';
import { AppDataProvider } from '@deriv-com/api-hooks';

createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
<QueryClientProvider client={new QueryClient()}>
<AppDataProvider>
<App />
</AppDataProvider>
</QueryClientProvider>
</StrictMode>
);

0 comments on commit 686c48b

Please sign in to comment.