{"version":3,"file":"index-DAM02M2W.js","sources":["../../src/features/auth/components/login-form/login-form.tsx","../../src/pages/login/login.tsx"],"sourcesContent":["import {\n LoginCred,\n useAuthGoogleGetAuthorizationMutation,\n useAuthLoginGoogleMutation,\n useAuthLoginMutation,\n useLazyAuthWhoamiQuery,\n} from '@app/services/auto-generated/auth'\nimport {\n Alert,\n Button,\n Container,\n Divider,\n InputAdornment,\n Link,\n TextField,\n Typography,\n} from '@common/components'\nimport {\n DASHBOARD_ROUTE,\n FORGET_ROUTE,\n MY_CLASSROOMS_ROUTE,\n PROFILE_ROUTE,\n REGISTER_ROUTE,\n VERIFY_ROUTE,\n} from '@common/constants/routes'\nimport { useTranslation } from '@common/hooks'\nimport { EmailIcon, GoogleIcon, KeyIcon } from '@common/icons'\nimport { yupResolver } from '@hookform/resolvers/yup'\nimport { SubmitHandler, useForm } from '@lib/form'\nimport { RouterLink, useNavigate, useSearchParams, useLocation } from '@lib/router'\nimport { isErrorResponse } from '@types'\nimport { urlEncodeEmail } from '@utils'\nimport React from 'react'\nimport { loginSchema } from '@common/utils/validations/auth.validations'\nimport { StyledTextField } from './login-form.styles'\nimport { useMediaQuery } from '@common/hooks'\n\nconst LoginForm: React.FC = () => {\n const isMobile = useMediaQuery(950)\n const [searchParams] = useSearchParams()\n const { t } = useTranslation('login-page')\n const navigate = useNavigate()\n const location = useLocation()\n\n const { handleSubmit, control, getValues } = useForm({\n defaultValues: {\n password: '',\n email: '',\n username: '',\n },\n resolver: yupResolver(loginSchema),\n })\n\n const parseJSON = (str: string) => {\n try {\n return JSON.parse(str)\n } catch (err) {\n return null\n }\n }\n\n const [login, { isLoading: isLoadingLogin, isError }] = useAuthLoginMutation()\n const [\n getGoogleAuth,\n { isLoading: isLoadingGetGoogleAuth, isSuccess: isSuccessGoogleAuthLogin },\n ] = useAuthGoogleGetAuthorizationMutation()\n const [loginWithGoogle, { isLoading: isLoadingLoginWithGoogle }] = useAuthLoginGoogleMutation()\n const [getUser] = useLazyAuthWhoamiQuery()\n\n const onSubmit: SubmitHandler = async (formState) => {\n try {\n if (formState.email === '') {\n formState.email = null\n }\n if (formState.username === '') {\n formState.username = null\n }\n\n try {\n await login({ loginCred: formState }).unwrap()\n } catch (err: any) {\n if (isErrorResponse(err)) {\n if (err.data.detail.error_code === 'EXC_USER_NOT_VERIFIED') {\n const email: string | undefined = getValues('email')\n if (email) {\n navigate(`${VERIFY_ROUTE}?email=${urlEncodeEmail(email)}`)\n }\n }\n }\n }\n await getUser().unwrap()\n } catch (err) {}\n if (formState.username === null) {\n formState.username = ''\n }\n if (formState.email === null) {\n formState.email = ''\n }\n }\n\n const handleGoogleLogin = async () => {\n try {\n const previousUrl = location.state?.from?.pathname || DASHBOARD_ROUTE\n console.log('previousUrl:', previousUrl)\n const state = encodeURIComponent(JSON.stringify({ realRedirectUrl: previousUrl }))\n const { url } = await getGoogleAuth({\n googleGetAuthorizationRequest: {\n redirect_url: `${window.location.origin}/`,\n state,\n },\n }).unwrap()\n window.location.href = url\n } catch (error) {\n console.error('Google login error:', error)\n }\n }\n\n // for google sign in\n const code = searchParams.get('code')\n const state = searchParams.get('state')\n\n const loginGoogleFlow = async () => {\n if (code) {\n await loginWithGoogle({\n googleLoginRequest: {\n code,\n redirect_url: `${window.location.origin}/`,\n ext: state ? parseJSON(decodeURIComponent(state)) : null,\n },\n }).unwrap()\n await getUser().unwrap()\n const parsedState = parseJSON(decodeURIComponent(state))\n if (parsedState && parsedState['realRedirectUrl'] === PROFILE_ROUTE) {\n navigate(MY_CLASSROOMS_ROUTE)\n return\n }\n if (parsedState) {\n window.location.href = parsedState['realRedirectUrl']\n }\n }\n }\n\n React.useEffect(() => {\n if (code) {\n loginGoogleFlow()\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [code])\n\n // if (isLoadingLoginWithGoogle) {\n // return (\n // \n // \n // \n // )\n // }\n\n return (\n \n \n {t('title', 'Returning users')}\n \n {isError && (\n \n Please verify your email and password\n \n )}\n \n \n \n ),\n }}\n fullWidth\n sx={{ mb: 2 }}\n />\n \n \n \n ),\n }}\n fullWidth\n sx={{ mb: 1 }}\n />\n \n {t('forget-password.typo', 'Forgot your password?')}{' '}\n \n {t('forget-password.link', 'Reset')}\n \n \n \n {t('submit-button.label', 'Login')}\n \n OR\n }\n sx={{ mb: 1 }}\n size={isMobile ? 'small' : 'medium'}\n >\n {t('google-button.label', 'Sign in with google')}\n \n \n {t('no-account.typo', \"Don't have an account?\")}{' '}\n \n {t('no-account.link', 'Register')}\n \n \n \n )\n}\n\nexport default LoginForm\n","import React from 'react'\nimport { Button, Link, Paper, Typography } from '@common/components'\nimport { CenterContainer } from '@common/containers'\nimport { LoginForm } from '@features/auth/components'\nimport { ThemeProvider } from '@common/utils/styles'\nimport pengguinLogo from '@assets/svg/pengguin-logo.svg'\nimport { useTranslation } from 'react-i18next'\nimport lightTheme from '@styles/themes/light-theme'\nimport { ArrowOutwardIcon } from '@common/icons'\nimport { RouterLink } from '@lib/router'\nimport { MAIN_ROUTE } from '@common/constants/routes'\nimport { useTheme } from '@features/theme/theme.hooks'\nimport isepakLogoDark from '@assets/svg/logo-speakduo-dark.svg'\n\nconst Login: React.FC = () => {\n const { t } = useTranslation('login-page')\n const { isDark } = useTheme()\n return (\n <>\n (theme.palette.mode === 'dark' ? 'white' : 'black'),\n },\n }}\n >\n Explore Events\n \n \n \n \n \n \n \n \n {t('title', 'Sign in')}\n \n \n \n \n \n )\n}\n\nexport default Login\n"],"names":["LoginForm","isMobile","useMediaQuery","searchParams","useSearchParams","t","useTranslation","navigate","useNavigate","location","useLocation","handleSubmit","control","getValues","useForm","yupResolver","loginSchema","parseJSON","str","login","isLoadingLogin","isError","useAuthLoginMutation","getGoogleAuth","isLoadingGetGoogleAuth","isSuccessGoogleAuthLogin","useAuthGoogleGetAuthorizationMutation","loginWithGoogle","isLoadingLoginWithGoogle","useAuthLoginGoogleMutation","getUser","useLazyAuthWhoamiQuery","onSubmit","formState","err","isErrorResponse","email","VERIFY_ROUTE","urlEncodeEmail","handleGoogleLogin","previousUrl","_b","_a","DASHBOARD_ROUTE","state","url","error","code","loginGoogleFlow","parsedState","PROFILE_ROUTE","MY_CLASSROOMS_ROUTE","React","jsxs","Container","jsx","Typography","Alert","StyledTextField","InputAdornment","EmailIcon","KeyIcon","Link","RouterLink","FORGET_ROUTE","Button","Divider","GoogleIcon","REGISTER_ROUTE","Login","isDark","useTheme","Fragment","MAIN_ROUTE","theme","ArrowOutwardIcon","CenterContainer","Paper","isepakLogoDark","pengguinLogo"],"mappings":"w7NAqCA,MAAMA,GAAsB,IAAM,CAC1B,MAAAC,EAAWC,EAAc,GAAG,EAC5B,CAACC,CAAY,EAAIC,GAAgB,EACjC,CAAE,EAAAC,CAAA,EAAMC,EAAe,YAAY,EACnCC,EAAWC,GAAY,EACvBC,EAAWC,GAAY,EAEvB,CAAE,aAAAC,EAAc,QAAAC,EAAS,UAAAC,CAAA,EAAcC,GAAmB,CAC9D,cAAe,CACb,SAAU,GACV,MAAO,GACP,SAAU,EACZ,EACA,SAAUC,GAAYC,CAAW,CAAA,CAClC,EAEKC,EAAaC,GAAgB,CAC7B,GAAA,CACK,OAAA,KAAK,MAAMA,CAAG,OACT,CACL,OAAA,IAAA,CAEX,EAEM,CAACC,EAAO,CAAE,UAAWC,EAAgB,QAAAC,CAAQ,CAAC,EAAIC,EAAqB,EACvE,CACJC,EACA,CAAE,UAAWC,EAAwB,UAAWC,EAAyB,GACvEC,EAAsC,EACpC,CAACC,EAAiB,CAAE,UAAWC,EAA0B,CAAA,EAAIC,EAA2B,EACxF,CAACC,CAAO,EAAIC,EAAuB,EAEnCC,EAAqC,MAAOC,GAAc,CAC1D,GAAA,CACEA,EAAU,QAAU,KACtBA,EAAU,MAAQ,MAEhBA,EAAU,WAAa,KACzBA,EAAU,SAAW,MAGnB,GAAA,CACF,MAAMd,EAAM,CAAE,UAAWc,CAAW,CAAA,EAAE,OAAO,QACtCC,EAAU,CACb,GAAAC,GAAgBD,CAAG,GACjBA,E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