Reputation: 11
I started this project (called playdate for no reason) to learn react and a few new aws resources so I'm positive I'm doing something stupid wrong. I want to use cognito's hosted sign in, but I can't seem to figure out how to get my "Cognito successful sign in screen" to go back to the actual react app.
import './App.css';
import { useAuth } from 'react-oidc-context';
function Playdate() {
const auth = useAuth();
const signOutRedirect = () => {
const clientId = 'clientidhere';
const logoutUri = 'thisFieldHasBeenAVarietyOfThings';
const cognitoDomain = 'myactualcognitodomainhere';
window.location.href = `${cognitoDomain}/logout?client_id=${clientId}&logout_uri=${encodeURIComponent(logoutUri)}`;
};
if (auth.isLoading) {
return <div>loading...</div>;
}
if (auth.error) {
return <div>Error... {auth.error.message}</div>;
}
const signInRedirect = () => {
const redirectUri = 'thisFieldHasBeenAVarietyOfThings';
auth.signinRedirect({ redirectUri });
};
if (auth.isAuthenticated) {
return (
<div>
<h1>playdateplaydateplaydate</h1>
<p>hello {auth.user?.profile.email}!</p>
<p>sign in worked</p>
<button onClick={() => auth.removeUser()}>sign out</button>
<button>this button should appear if auth successfully redirected </button>
</div>
);
}
return (
<div>
<h1>main sign in page here</h1>
<button onClick={() => auth.signinRedirect()}>sign in</button>
<button onClick={() => signOutRedirect()}>sign out</button>
</div>
);
}
export default Playdate;
all the fields here where i say it's been a few things are ones where I'm truly and genuinely not sure what putting there will yield a successful result. I read the docs and I took the suggestions to no success, and I can't seem to find any videos that can help with the hosted UI. I guess that service is relatively new. I've also tried all the suggestions that AI had at this point to no success. My closest to success has been with the correct clientID, the default cognito cloudfront URL it gives you when you set it up, my cognito domain as it's provided under branding>domain, and the const redirectUri being the default cognito cloudfront URL it gives you when you set it up. Thank you and I'm sorry in advance for anything stupid I'm misunderstanding
Upvotes: 1
Views: 27