mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-25 03:49:11 +00:00
feat(web): wire up discord auth button
This commit is contained in:
parent
0a399938d6
commit
3a36d7a85d
2 changed files with 16 additions and 3 deletions
|
@ -8,16 +8,21 @@ const Login = () => {
|
||||||
// If ?r is in query, then let's render the slug page
|
// If ?r is in query, then let's render the slug page
|
||||||
// If not, redirect.
|
// If not, redirect.
|
||||||
const [guildSlug, setGuildSlug] = React.useState<GuildSlug | null>(null);
|
const [guildSlug, setGuildSlug] = React.useState<GuildSlug | null>(null);
|
||||||
|
const [oauthLink, setOauthLink] = React.useState(`${apiUrl}/login-bounce`);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const url = new URL(window.location.href);
|
const url = new URL(window.location.href);
|
||||||
const callbackHost = new URL('/', url);
|
const callbackHost = new URL('/', url);
|
||||||
const redirectServerID = url.searchParams.get('r');
|
const redirectServerID = url.searchParams.get('r');
|
||||||
|
const redirectUrl = `${apiUrl}/login-bounce?cbh=${callbackHost.href}`;
|
||||||
if (!redirectServerID) {
|
if (!redirectServerID) {
|
||||||
window.location.href = `${apiUrl}/login-bounce?cbh=${callbackHost.href}`;
|
window.location.href = redirectUrl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setOauthLink(redirectUrl);
|
||||||
|
localStorage.setItem('rp_postauth_redirect', `/s/${redirectServerID}`);
|
||||||
|
|
||||||
const fetchGuildSlug = async (id: string) => {
|
const fetchGuildSlug = async (id: string) => {
|
||||||
const response = await fetch(`/get-slug/${id}`);
|
const response = await fetch(`/get-slug/${id}`);
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
|
@ -33,7 +38,13 @@ const Login = () => {
|
||||||
return <div>Loading...</div>;
|
return <div>Loading...</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <AuthLogin guildSlug={guildSlug} onSendSecretCode={() => {}} />;
|
return (
|
||||||
|
<AuthLogin
|
||||||
|
guildSlug={guildSlug}
|
||||||
|
onSendSecretCode={() => {}}
|
||||||
|
discordOAuthLink={oauthLink}
|
||||||
|
/>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Login;
|
export default Login;
|
||||||
|
|
|
@ -5,8 +5,10 @@ const NewSession = () => {
|
||||||
const url = new URL(window.location.href);
|
const url = new URL(window.location.href);
|
||||||
const id = url.searchParams.get('session_id');
|
const id = url.searchParams.get('session_id');
|
||||||
if (id) {
|
if (id) {
|
||||||
window.location.href = '/';
|
|
||||||
localStorage.setItem('rp_session_key', id);
|
localStorage.setItem('rp_session_key', id);
|
||||||
|
|
||||||
|
const redirectUrl = localStorage.getItem('rp_postauth_redirect');
|
||||||
|
window.location.href = redirectUrl || '/';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue