Skip to content

Commit

Permalink
feat: 직업 선택 API 연동 (#50)
Browse files Browse the repository at this point in the history
* logout

* select job

* auth

* script
  • Loading branch information
woo-jk authored Aug 29, 2024
1 parent db168dd commit bd17907
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/app/login/api/usePutUserJob.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { http } from '@/apis/http';
import { useMutation } from '@tanstack/react-query';

type JobType = '개발자' | '디자이너';

const putUserJob = async (job: JobType) => http.put({ url: '/users/job', data: { job } });

export const usePutUserJob = () => useMutation({ mutationFn: putUserJob });
18 changes: 15 additions & 3 deletions src/app/login/components/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,25 @@ import { cn } from '@/utils';
import { useState } from 'react';
import { useSession } from 'next-auth/react';
import { useRouter } from 'next/navigation';
import { usePutUserJob } from '../api/usePutUserJob';

const jobMapper = {
developer: '개발자',
designer: '디자이너',
} as const;

export default function Select() {
const [position, setPosition] = useState<'designer' | 'developer' | ''>('');
const session = useSession();
const { push } = useRouter();
const { mutateAsync } = usePutUserJob();

const handleSubmit = async () => {
if (position === '') return;

await mutateAsync(jobMapper[position]);
push('/');
};

return (
<motion.section
Expand Down Expand Up @@ -66,9 +80,7 @@ export default function Select() {
'bg-neutral-5 rounded-6 py-13 h-48 px-20 w-full text-15 font-semibold text-neutral-30 transition-all',
position !== '' && 'text-white bg-[black]',
)}
onClick={() => {
push('/');
}}>
onClick={handleSubmit}>
선택 완료
</TouchButton>
</motion.section>
Expand Down
2 changes: 2 additions & 0 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
return session;
},
},

secret: process.env.NEXTAUTH_SECRET,
});

declare module 'next-auth' {
Expand Down

0 comments on commit bd17907

Please sign in to comment.