import Auth from "@aws-amplify/auth" ; import { CognitoHostedUIIdentityProvider } from "@aws-amplify/auth/lib/types" ; export const configAuth = ( ) => { const authRedirectPath = window . location . protocol + "//" + window . location . host + "/verify" ; const authSignOutPath = window . location . protocol + "//" + window . location . host + "/" ; const config = { Auth : { region : "ap-northeast-1" , userPoolId : "ap-northeast-1_dKhj1aZQy" , userPoolWebClientId : "4i0q5hl5u27mili6fnpvjap8fc" , mandatorySignIn : true , oauth : { domain : "auth.wasedatime.com" , scope : [ "email" , "profile" , "openid" , "aws.cognito.signin.user.admin" ] , redirectSignIn : authRedirectPath , redirectSignOut : authSignOutPath , responseType : "code" } } } ; Auth . configure ( config ) ; } ; export const getIdToken = async ( ) => { const session = await Auth . currentSession ( ) ; if ( session ) return session . getIdToken ( ) . getJwtToken ( ) || "" ; } ; export const getAccessToken = async ( ) => { const session = await Auth . currentSession ( ) ; if ( session ) return session . getAccessToken ( ) . getJwtToken ( ) || "" ; } ; export const getRefreshToken = async ( ) => { const session = await Auth . currentSession ( ) ; if ( session ) return session . getRefreshToken ( ) . getToken ( ) || "" ; } ; export const getUserAttr = async ( ) => { const info = await Auth . currentUserInfo ( ) ; if ( info && info . attributes ) return ( { id : info . attributes . sub , name : info . attributes . preferred_username , picture : info . attributes . picture } || null ) ; } ; export const signIn = ( ) => { try { Auth . federatedSignIn ( { provider : CognitoHostedUIIdentityProvider . Google , customState : window . location . pathname + window . location . search } ) ; } catch ( e ) { console . log ( e ) ; } } ; export const signOut = ( ) => { Auth . signOut ( ) ; } ;