Skip to content

Commit

Permalink
fix: 재가입 로직 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
cobocho committed Jul 18, 2024
1 parent afc6bfd commit 166da17
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 15 deletions.
3 changes: 2 additions & 1 deletion apps/web/.env.development
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
NEXT_PUBLIC_DOMAIN=http://localhost:3000
NEXT_PUBLIC_API_URL=https://dev-api.vook.app
NEXT_PUBLIC_API_URL=https://dev-api.vook.app
NEXT_PUBLIC_GOOGLE_LOGIN_URL=https://dev-api.vook.app/oauth2/authorization/google
15 changes: 11 additions & 4 deletions apps/web/src/app/(beforeLogin)/auth/token/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ const AuthCallbackPage = ({
const checkUserRegistered = async () => {
const userInfo = await userService.userInfo(queryClient)
const isRegistered = userInfo.result.status === UserStatus.Registered
const isOnboardingCompleted = userInfo.result.onboardingCompleted

if (isRegistered) {
router.push('/workspace')
if (!isOnboardingCompleted) {
router.push('/onboarding/funnel')
return
}

if (isRegistered && isOnboardingCompleted) {
const sendToken = () => {
window.postMessage(
{
Expand All @@ -59,9 +63,12 @@ const AuthCallbackPage = ({
sendToken()
}

return
router.push('/workspace')
}

if (userInfo.result.onboardingCompleted) {
router.push('/signup')
}
router.push('/signup')
}

checkUserRegistered()
Expand Down
13 changes: 5 additions & 8 deletions apps/web/src/app/(onboarding)/onboarding/job/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import React from 'react'
import { OnboardingJob, useOnboardingMutation } from '@vook-client/api'
import { useRouter } from 'next/navigation'

import { Link } from '@/components/Link'

import { SelectBoxGroup } from '../_components/SelectBoxGroup'
import { useOnBoarding } from '../_context/useOnboarding'
import { OnboardingHeader } from '../_components/OnboardingHeader'

import { buttonGroup, header, jobGroup, skipButton } from './page.css'
import { buttonGroup, header, jobGroup } from './page.css'

const JOBS: Array<{
icon: ButtonProps['prefixIcon']
Expand Down Expand Up @@ -114,13 +116,8 @@ const OnboardingJobPage = () => {
))}
</SelectBoxGroup>
</div>
<div className={buttonGroup}>
<Text
type="body-2"
color="label-alternative"
onClick={onSubmitFunnel}
className={skipButton}
>
<div className={buttonGroup} style={{ cursor: 'pointer' }}>
<Text type="body-2" color="label-alternative" onClick={onSubmitFunnel}>
건너뛰기
</Text>
<Link href="/onboarding/job">
Expand Down
30 changes: 28 additions & 2 deletions apps/web/src/components/SignUpForm/SignUpForm.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
'use client'

import { Button, Checkbox, Input, Text } from '@vook-client/design-system'
import { useSignUpMutation, useUserInfoQuery } from '@vook-client/api'
import {
UserStatus,
useSignUpMutation,
useUserInfoQuery,
} from '@vook-client/api'
import { useForm } from 'react-hook-form'
import { zodResolver } from '@hookform/resolvers/zod'
import { ChangeEventHandler, useMemo } from 'react'
import { useRouter } from 'next/navigation'
import z from 'zod'
import { useReRegisterMutation } from 'node_modules/@vook-client/api/src/services/auth/queries'

import {
checkboxGroup,
Expand Down Expand Up @@ -52,6 +57,19 @@ export const SignUpForm = () => {
},
)

const reSignUpMutation = useReRegisterMutation(
{
nickname: watch('nickname'),
requiredTermsAgree: watch('requiredTermsAgree'),
marketingEmailOptIn: watch('marketingEmailOptIn'),
},
{
onSuccess: () => {
router.push('/onboarding')
},
},
)

const isAllChecked =
watch('requiredTermsAgree') &&
watch('policyAgree') &&
Expand All @@ -77,7 +95,15 @@ export const SignUpForm = () => {
const email = userInfoQuery.data.result.email

const onSubmit = handleSubmit(() => {
signUpMutation.mutate()
if (!userInfoQuery.data) {
return
}

if (userInfoQuery.data.result.status === UserStatus.Withdrawn) {
reSignUpMutation.mutate()
} else {
signUpMutation.mutate()
}
})

const onCheckAll: ChangeEventHandler<HTMLInputElement> = (e) => {
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const onlyRegisteredMiddleware = checkUserStatusMiddleware([

const onlyUnregisteredSocialUser = checkUserStatusMiddleware([
UserStatus.SocialLoginCompleted,
UserStatus.Withdrawn,
])

export async function middleware(req: NextRequest) {
Expand Down
15 changes: 15 additions & 0 deletions packages/api/src/services/auth/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,26 @@ export const authOptions = {
register: (client: QueryClient, dto: SignUpDTO) => ({
mutationFn: () => authService.register(client, dto),
}),
reRegister: (client: QueryClient, dto: SignUpDTO) => ({
mutationFn: () => authService.reRegister(client, dto),
}),
withdraw: (client: QueryClient) => ({
mutationFn: () => authService.withdraw(client),
}),
}

export const useReRegisterMutation = (
dto: SignUpDTO,
options: MutationOptions<SignUpResponse> = {},
) => {
const queryClient = useQueryClient()

return useMutation<SignUpResponse>({
...authOptions.reRegister(queryClient, dto),
...options,
})
}

export const useSignUpMutation = (
dto: SignUpDTO,
options: MutationOptions<SignUpResponse> = {},
Expand Down
9 changes: 9 additions & 0 deletions packages/api/src/services/auth/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ export const authService = {
})
},

async reRegister(client: QueryClient, dto: SignUpDTO) {
return APIBuilder.post('/user/re-register')
.withCredentials(client)
.build()
.call<SignUpResponse>({
body: JSON.stringify(dto),
})
},

async withdraw(client: QueryClient) {
return APIBuilder.post('/user/withdraw')
.withCredentials(client)
Expand Down

0 comments on commit 166da17

Please sign in to comment.