Skip to content

Commit

Permalink
Refactor authentication screens and password reset
Browse files Browse the repository at this point in the history
logic
  • Loading branch information
Timothy Miller committed Nov 6, 2023
1 parent 2ebf40b commit 502b8e4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 34 deletions.
17 changes: 5 additions & 12 deletions packages/app/features/password-reset/screen.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { YStack, useToastController } from '@t4/ui'
import { useRouter } from 'solito/router'
import { PasswordResetComponent } from '@t4/ui/src/PasswordReset'
import { isExpoGo } from 'app/utils/flags'
import { useSessionRedirect, useSignIn } from 'app/utils/auth'
import { TRPCClientError } from '@trpc/client'

Expand All @@ -15,9 +14,7 @@ export function PasswordResetScreen() {
try {
// Send email with the password reset link
const res = await signIn({ email })
if (!isExpoGo) {
toast.show('Password reset email sent')
}
toast.show('Password reset email sent')
push('/login')
} catch (error) {
if (error) {
Expand All @@ -26,15 +23,11 @@ export function PasswordResetScreen() {
error.data?.httpStatus &&
error.data.httpStatus < 500
) {
if (!isExpoGo) {
toast.show(error.message)
}
toast.show(error.message)
} else {
if (!isExpoGo) {
toast.show('Password reset request failed', {
description: error.message,
})
}
toast.show('Password reset request failed', {
description: error.message,
})
}
console.log('Password reset request failed', error)
}
Expand Down
20 changes: 8 additions & 12 deletions packages/app/features/password-reset/update-password/screen.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { YStack, useToastController } from '@t4/ui'
import { useRouter } from 'solito/router'
import { PasswordResetComponent } from '@t4/ui/src/PasswordReset'
import { isExpoGo } from 'app/utils/flags'
import { createParam } from 'solito'
import { useSessionRedirect, useSignIn } from 'app/utils/auth'
import { TRPCClientError } from '@trpc/client'
Expand All @@ -24,9 +23,10 @@ export function UpdatePasswordScreen() {
const email = params.email
const code = params.code
if (!email || !code) {
if (!isExpoGo) {
toast.show('Sorry, the update password link is missing params. Try resetting your password again.')
}
toast.show(
'Sorry, the update password link is missing params. Try resetting your password again.'
)

push('/password-reset')
return
}
Expand All @@ -39,15 +39,11 @@ export function UpdatePasswordScreen() {
error.data?.httpStatus &&
error.data.httpStatus < 500
) {
if (!isExpoGo) {
toast.show(error.message)
}
toast.show(error.message)
} else {
if (!isExpoGo) {
toast.show('Password change failed', {
description: error.message,
})
}
toast.show('Password change failed', {
description: error.message,
})
}
console.log('Password change failed', error)
}
Expand Down
3 changes: 1 addition & 2 deletions packages/app/features/sign-in/screen.native.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { AuthProviderName } from '@t4/api/src/auth/providers'
import { YStack, useToastController } from '@t4/ui'
import { capitalizeWord } from '@t4/ui/src/libs/string'
import { SignUpSignInComponent } from 'app/features/sign-in/SignUpSignIn'
import { useSessionRedirect, useSignIn } from 'app/utils/auth'
import { initiateAppleSignIn } from 'app/utils/auth/appleAuth'
import { storeSessionToken } from 'app/utils/auth/credentials'
import { isExpoGo } from 'app/utils/flags'
import { capitalizeWord } from 'app/utils/string'
import { trpc } from 'app/utils/trpc'
import { getInitialURL } from 'expo-linking'
import * as WebBrowser from 'expo-web-browser'
Expand Down
2 changes: 1 addition & 1 deletion packages/app/features/sign-in/screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TRPCClientError } from '@trpc/client'
import { SignUpSignInComponent } from 'app/features/sign-in/SignUpSignIn'
import { useRouter } from 'solito/router'
import { useSessionRedirect, useSignIn } from 'app/utils/auth'
import { capitalizeWord } from 'app/utils/string'
import { capitalizeWord } from '@t4/ui/src/libs/string'

export const SignInScreen = (): React.ReactNode => {
const toast = useToastController()
Expand Down
11 changes: 4 additions & 7 deletions packages/app/features/sign-up/screen.native.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { AuthProviderName } from '@t4/api/src/auth/providers'
import { YStack, useToastController } from '@t4/ui'
import { capitalizeWord } from '@t4/ui/src/libs/string'
import { SignUpSignInComponent } from 'app/features/sign-in/SignUpSignIn'
import { useSignIn, useSignUp } from 'app/utils/auth'
import { initiateAppleSignIn } from 'app/utils/auth/appleAuth'
import { storeSessionToken } from 'app/utils/auth/credentials'
import { isExpoGo } from 'app/utils/flags'
import { capitalizeWord } from 'app/utils/string'
import { trpc } from 'app/utils/trpc'
import { getInitialURL } from 'expo-linking'
import * as WebBrowser from 'expo-web-browser'
Expand Down Expand Up @@ -82,11 +81,9 @@ export const SignUpScreen = (): React.ReactNode => {
password,
})
} catch (error) {
if (!isExpoGo) {
toast.show('Sign up failed', {
description: error.message,
})
}
toast.show('Sign up failed', {
description: error.message,
})
console.log('Sign up failed', error)
}
}
Expand Down

0 comments on commit 502b8e4

Please sign in to comment.