Skip to content

Commit

Permalink
resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
musordmt committed Jul 12, 2024
2 parents 2e453c2 + 177ed9a commit a3a7d78
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 29 deletions.
6 changes: 3 additions & 3 deletions packages/auth/components/email-password-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ const EmailPasswordForm: React.FC<{
isLoading: boolean
className?: string
inputClx?: string
content?: string
prompt?: string
}> = ({
onSubmit,
isLoading,
className,
inputClx,
content='Login'
prompt='Login'
}) => {
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
Expand Down Expand Up @@ -84,7 +84,7 @@ const EmailPasswordForm: React.FC<{
</FormItem>
)}
/>
<Button type='submit' className='w-full' disabled={isLoading}>{content}</Button>
<Button type='submit' className='w-full' disabled={isLoading}>{prompt}</Button>
</form>
</Form>
)
Expand Down
30 changes: 20 additions & 10 deletions packages/auth/components/login-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ProviderLoginButton: React.FC<PropsWithChildren & {

return (
<Button
onClick={() => loginWithProvider(provider)}
onClick={() => {loginWithProvider(provider)}}
className='w-full mx-auto flex items-center gap-2'
disabled={isLoading}
variant='outline'
Expand Down Expand Up @@ -69,8 +69,8 @@ const LoginPanel: React.FC<PropsWithChildren & {
sendGAEvent('login', { method: loginMethod })
}

// If a callback is provided, don't redirect.
// Assume host code is handling (eg, mobile menu)
// If a callback is provided, don't redirect.
// Assume host code is handling (eg, mobile menu)
if (onLoginChanged) {
const res = await fetch(
'/api/auth/generate-custom-token',
Expand All @@ -79,7 +79,7 @@ const LoginPanel: React.FC<PropsWithChildren & {
onLoginChanged(res.token?.token ?? null)
}
else if (redirectUrl) {
// TODO :aa shouldn't the token thing happen in this case too??
// TODO :aa shouldn't the token thing happen in this case too??
router.push(redirectUrl)
}
}
Expand All @@ -88,8 +88,12 @@ const LoginPanel: React.FC<PropsWithChildren & {
setIsLoading(true)
try {
const res = await auth.loginEmailAndPassword(email, password)
if (res.success) { succeed('email'); toast.success(res.message) }
else { toast.error(res.message) }
if (res.success) {
succeed('email'); toast.success(res.message)
}
else {
toast.error(res.message)
}
}
catch (e) {
toast('User with this email already signed up using a different provider')
Expand All @@ -116,19 +120,25 @@ const LoginPanel: React.FC<PropsWithChildren & {
const loginWithProvider = async (provider: AuthProvider) => {
setIsLoading(true)
const res = await auth.loginWithProvider(provider)
if (res.success) { succeed(provider) }
if (res.success) {
succeed(provider)
}
setIsLoading(false)
}

const logout = async () => {
setIsLoading(true)
const res = await auth.logout()
if (res.success) { succeed(null) }
if (res.success) {
succeed(null)
}
setIsLoading(false)
}

const handleOnClick = () => {
if (setIsLogin) setIsLogin(false)
if (setIsLogin) {
setIsLogin(false)
}
}

return (
Expand All @@ -140,7 +150,7 @@ const LoginPanel: React.FC<PropsWithChildren & {
<p>You are signed in as {auth.user?.displayName ?? auth.user?.email}</p>
<div className='flex flex-col md:flex-row gap-3 items-center justify-center'>
{getStartedUrl && <Button variant='primary' onClick={() => router.push(getStartedUrl)} className='w-full'>GET STARTED</Button>}
<Button onClick={() => logout()} variant='outline' disabled={isLoading} className='w-full'>Sign Out</Button>
<Button onClick={logout} variant='outline' disabled={isLoading} className='w-full'>Sign Out</Button>
</div>
</>)}
</>
Expand Down
46 changes: 31 additions & 15 deletions packages/auth/components/signup-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ const SignupPanel: React.FC<PropsWithChildren & {
sendGAEvent('login', { method: loginMethod })
}

// If a callback is provided, don't redirect.
// Assume host code is handling (eg, mobile menu)
// If a callback is provided, don't redirect.
// Assume host code is handling (eg, mobile menu)
if (onLoginChanged) {
const res = await fetch(
'/api/auth/generate-custom-token',
Expand All @@ -79,7 +79,7 @@ const SignupPanel: React.FC<PropsWithChildren & {
onLoginChanged(res.token?.token ?? null)
}
else if (redirectUrl) {
// TODO :aa shouldn't the token thing happen in this case too??
// TODO :aa shouldn't the token thing happen in this case too??
router.push(redirectUrl)
}
}
Expand All @@ -88,8 +88,13 @@ const SignupPanel: React.FC<PropsWithChildren & {
setIsLoading(true)
try {
const res = await auth.signupEmailAndPassword(email, password)
if (res.success) { succeed('email'); toast.success(res.message) }
else { toast.error(res.message) }
if (res.success) {
succeed('email')
toast.success(res.message)
}
else {
toast.error(res.message)
}
}
catch (e) {
toast.success('User with this email already signed up')
Expand All @@ -116,44 +121,55 @@ const SignupPanel: React.FC<PropsWithChildren & {
const loginWithProvider = async (provider: AuthProvider) => {
setIsLoading(true)
const res = await auth.loginWithProvider(provider)
if (res.success) { succeed(provider) }
if (res.success) {
succeed(provider)
}
setIsLoading(false)
}

const logout = async () => {
setIsLoading(true)
const res = await auth.logout()
if (res.success) { succeed(null) }
if (res.success) {
succeed(null)
}
setIsLoading(false)
}

const handleOnClick = () => {
if (setIsLogin) setIsLogin(true)
if (setIsLogin) {
setIsLogin(true)
}
}

return (
<ApplyTypography className={cn('w-full flex flex-col text-center !gap-3 LOGIN_OUTER', className)}>
<ApplyTypography className={cn('w-full flex flex-col text-center !gap-3', className)}>
{auth.loggedIn && !redirectUrl ? (
<>
<h4>Welcome!</h4>
{auth.user && (<> {/* this means the hanzo user isn't loaded yet ...*/}
<p>You are signed in as {auth.user?.displayName ?? auth.user?.email}</p>
<div className='flex flex-col md:flex-row gap-3 items-center justify-center'>
{getStartedUrl && <Button variant='primary' onClick={() => router.push(getStartedUrl)} className='w-full'>GET STARTED</Button>}
<Button onClick={() => logout()} variant='outline' disabled={isLoading} className='w-full'>Sign Out</Button>
{getStartedUrl && <Button variant='primary' onClick={() => {router.push(getStartedUrl)}} className='w-full'>GET STARTED</Button>}
<Button onClick={logout} variant='outline' disabled={isLoading} className='w-full'>Sign Out</Button>
</div>
</>)}
</>
) : (
<>
{!noHeading && (
<h4 className='text-center'>SignUp</h4>
<h4 className='text-center'>Sign Up</h4>
)}
{children}
<EmailPasswordForm onSubmit={signupWithEmailPassword} isLoading={isLoading} className='mb-4' inputClx={inputClx} content='SignUp' />

<EmailPasswordForm
onSubmit={signupWithEmailPassword}
isLoading={isLoading}
className='mb-4'
inputClx={inputClx}
prompt='SignUp'
/>
<div className='flex flex-row gap-4 justify-center'>
<div className='text-muted-2 text-sm'>Already have account?</div>
<div className='text-muted-2 text-sm'>Already have an account?</div>
<button className='bg-transparent text-foreground text-sm' onClick={handleOnClick}>Log In</button>
</div>

Expand Down
2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hanzo/auth",
"version": "2.4.12",
"version": "2.4.14",
"description": "Library with Firebase authentication.",
"publishConfig": {
"registry": "https://registry.npmjs.org/",
Expand Down

0 comments on commit a3a7d78

Please sign in to comment.