From 4feda40d8eda511e45071375044d2e6f262fce78 Mon Sep 17 00:00:00 2001 From: TheNozomi <13172293+TheNozomi@users.noreply.github.com> Date: Fri, 9 Jul 2021 18:33:26 -0300 Subject: [PATCH 01/17] feat: discord authentication --- src/components/Auth/SignInForm.jsx | 45 ++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/components/Auth/SignInForm.jsx b/src/components/Auth/SignInForm.jsx index 843b4dd..bee4930 100644 --- a/src/components/Auth/SignInForm.jsx +++ b/src/components/Auth/SignInForm.jsx @@ -4,6 +4,7 @@ import { motion } from 'framer-motion' import { Dialog } from '@headlessui/react' import { yupResolver } from '@hookform/resolvers/yup' import * as yup from 'yup' +import Image from 'next/image' import { Input } from '@/components/Input' import { Button } from '@/components/Button' @@ -22,6 +23,8 @@ const schema = yup.object().shape({ export const SignIn = ({ onComplete, onRequestSignUp, unauthorizedMessage }) => { const [loading, setLoading] = useState(false) const [error, setError] = useState(null) + const [discordButtonLoading, setDiscordButtonLoading] = useState(false) + const [discordAuthError, setDiscordAuthError] = useState(null) const { register, handleSubmit, formState } = useForm({ resolver: yupResolver(schema), }) @@ -46,11 +49,33 @@ export const SignIn = ({ onComplete, onRequestSignUp, unauthorizedMessage }) => } } + const discordAuth = async () => { + setDiscordAuthError(null) + setDiscordButtonLoading(true) + try { + const { user, error } = await supabase.auth.signIn({ + provider: 'discord' + }, { + redirectTo: window.location.href + }) + + if (error) { + throw error + } else { + onComplete(user) + } + } catch(error) { + setError(error.error_description || error.message) + } finally { + setDiscordButtonLoading(false) + } + } + return (
{getErrorMessage(discordAuthError)}
{JSON.stringify(user, null, 2)}}
+ Querés cambiar de cuenta cuenta o salir?
{JSON.stringify(user, null, 2)}}
- Querés cambiar de cuenta cuenta o salir?
+Querés cambiar de cuenta cuenta o salir?
{getErrorMessage(discordAuthError)}
+{getErrorMessage(discordAuthError)}
{author}
*/} -- {publishedAt && format(parseISO(publishedAt), 'MMMM dd, yyyy')} -
++ {publishedAt && format(parseISO(publishedAt), 'MMMM dd, yyyy')} +
++ {author || null} +
+Próximamente
+Próximamente en PDF
)}{JSON.stringify(user, null, 2)}}
- Querés cambiar de cuenta cuenta o salir?
++ Querés cambiar de cuenta cuenta o salir? +