You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to provide 2 ways to my user to login :
1 - Credentials
2 - Using SAML identity providers with a user pool
When trying to login with the second option using signInWithRedirect({ custom: custom-provider }), I can see that the oauth2/authorize call is done in the network, and I also see the following call which is http://localhost:3000/?code=[Authorization_Code]&state=[State_Code]
Afterword, there is no connection done, not even cookies saved.
Expected behavior
The user to be authentified, so I can retrieve the user informations for my application.
Reproduction steps
Create new NextJS project
Configure SAML identity provider with Cognito
Create custom login page, and add following code as the button for sso connection (which is signInWithRedirect)
Code Snippet
// Put your code below this line.'use client'importBoxfrom'@mui/material/Box/Box'importButtonfrom'@mui/material/Button/Button'import{AuthUser,getCurrentUser,signInWithRedirect}from'aws-amplify/auth';import{useRouter}from'next/navigation';import{useEffect,useState}from'react';import{Hub}from'aws-amplify/utils';import'aws-amplify/auth/enable-oauth-listener';functionSSOButton(){constrouter=useRouter();constprovider={custom: 'custom-provider'}const[user,setUser]=useState<AuthUser|null>(null);const[error,setError]=useState<unknown>(null);const[customState,setCustomState]=useState<string|null>(null);useEffect(()=>{constunsubscribe=Hub.listen("auth",({ payload })=>{switch(payload.event){case"signInWithRedirect":
console.log('it worked !')getUser();break;case"signInWithRedirect_failure":
setError("An error has occurred during the OAuth flow.");break;case"customOAuthState":
setCustomState(payload.data);// this is the customState provided on signInWithRedirect functionconsole.log(customState)break;}});getUser();returnunsubscribe;},[]);constgetUser=async(): Promise<void>=>{try{constcurrentUser=awaitgetCurrentUser();setUser(currentUser);router.push('/');}catch(error){console.error(error);console.log("Not signed in");}};return(<Boxcomponent="div"sx={{mt: 3}}><Buttonvariant="contained"onClick={()=>signInWithRedirect({provider,customState: "custom-state"})}>SSOConnexion</Button></Box>)}exportdefaultSSOButton;
Log output
The only info I receive from the call is an undefined value that I print.
Hey, @jojimcNova 👋. When you state that you're using a custom login page, is it a different URL than what is specified in your config (which is "http://localhost:3000/" it looks like)?
Hi @cwomack, currently, I have the login page in the following url : http://localhost:3000/login. I use a middleware to redirect to /login if the user is not login. If he's authenticated, I redirect him to http://localhost:3000/
Before opening, please confirm:
JavaScript Framework
Next.js
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth
Backend
None
Environment information
Describe the bug
I'm trying to provide 2 ways to my user to login :
1 - Credentials
2 - Using SAML identity providers with a user pool
When trying to login with the second option using
signInWithRedirect({ custom: custom-provider })
, I can see that the oauth2/authorize call is done in the network, and I also see the following call which ishttp://localhost:3000/?code=[Authorization_Code]&state=[State_Code]
Afterword, there is no connection done, not even cookies saved.
Expected behavior
The user to be authentified, so I can retrieve the user informations for my application.
Reproduction steps
Code Snippet
Log output
The only info I receive from the call is an
undefined
value that I print.aws-exports.js
No response
Manual configuration
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: