Last active
January 28, 2025 12:54
-
-
Save ognis1205/b72664260fbc30daa3c5412e90164530 to your computer and use it in GitHub Desktop.
OktaSignInWidget.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect } from 'react'; | |
import OktaSignIn from '@okta/okta-signin-widget'; | |
interface OktaSignInWidgetProps { | |
onSuccess: (tokens: any) => void; | |
onError: (error: Error) => void; | |
} | |
export default function OktaSignInWidget({ | |
onSuccess, | |
onError, | |
}: OktaSignInWidgetProps) { | |
useEffect(() => { | |
const widget = new OktaSignIn({ | |
clientId: process.env.REACT_APP_OKTA_CLIENT_ID, | |
redirectUri: window.location.origin, | |
issuer: | |
'https://' + process.env.REACT_APP_OKTA_DOMAIN + '/oauth2/default', | |
logo: '/uc-logo.png', | |
}); | |
widget.showSignInToGetTokens({ | |
el: '#osw-container', | |
}) | |
.then(function (res) { | |
onSuccess(res?.idToken?.idToken); | |
widget.remove(); | |
}) | |
.catch(function (error) { | |
onError(error); | |
}); | |
return () => widget.remove(); | |
}, [onSuccess, onError]); | |
return <div id={'osw-container'} />; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment