Skip to content

Commit

Permalink
Merge pull request #57 from SproutMJ/develop
Browse files Browse the repository at this point in the history
수정사항 적용
  • Loading branch information
SproutMJ authored Jun 1, 2024
2 parents 33e8a08 + 14d6705 commit 87e6758
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class UserController {
private final UserService userService;

@PostMapping("/signup")
public ResponseEntity<?> signup(@RequestBody @Valid SignupRequestDto signupRequestDto) {
public ResponseEntity<StatusResponseDto> signup(@RequestBody @Valid SignupRequestDto signupRequestDto) {
return userService.signup(signupRequestDto);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public ResponseEntity<StatusResponseDto> signup(SignupRequestDto requestDto) {
// 회원 중복 확인
Optional<User> checkUsername = userRepository.findByUserName(userName);
if (checkUsername.isPresent()) {
throw new IllegalArgumentException("중복된 사용자가 존재합니다.");
StatusResponseDto res = new StatusResponseDto("중복된 사용자가 존재합니다", 401);
System.out.println("중복!!!");
return new ResponseEntity<>(res, HttpStatus.OK);
}

// 사용자 등록
Expand Down
38 changes: 26 additions & 12 deletions frontend/src/app/signup/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ import { Button } from "@/components/ui/button"
import {useState} from "react";
import {useRouter} from "next/navigation";

interface SignUpResponse {
msg: string;
statuscode: number;
}

export default function SignUp() {
const [id, setId] = useState('');
const [password, setPassword] = useState('');
Expand All @@ -43,20 +48,29 @@ export default function SignUp() {
};

async function signUp() {
const userName = id;
const res = await fetch('/api/signup',{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({userName, password})
});
if (password === confirmPassword) {
const userName = id;
const res = await fetch('/api/signup',{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({userName, password})
});

if (!res.ok) {
throw new Error('Failed to fetch data')
}
const data: SignUpResponse = await res.json();
console.log(data);

router.push('/login')
if (data.statuscode === 401) {
alert(data.msg);
} else if (!res.ok) {
throw new Error('Failed to fetch data');
} else {
router.push('/login');
}
} else {
alert('비밀번호가 일치하지 않습니다');
}
}

return (
Expand Down

0 comments on commit 87e6758

Please sign in to comment.