Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ› : μ‚¬μš©μž λ‹‰λ„€μž„ κ·œμΉ™μ— λŒ€ν•œ ν΄λΌμ΄μ–ΈνŠΈ 검증 #209

Merged
merged 1 commit into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions front-end/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ export const OAUTH_LIST: { type: string }[] = [
type: 'github',
},
];

export const NICKNAME_REGEX = /^[γ„±-γ…Ž|κ°€-힣|a-z|A-Z|0-9|]+$/;
27 changes: 16 additions & 11 deletions front-end/src/pages/ProfilePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { updateNickname } from '../../features/user/userSlice';
import { useSocket, useSocketReady } from '../../context/SocketContext';
import InfiniteScroll from '../../components/InfiniteScroll';
import { fetchGetStateMessage, fetchGetTotal, fetchUpdateUserState } from './profileFetch';
import { NICKNAME_REGEX } from '../../constants';

const recentHeader = ['λ‚ μ§œ', 'λͺ¨λ“œ', 'λ“±μˆ˜', 'ν”Œλ ˆμ΄ νƒ€μž„', '곡격 횟수', '받은 횟수'];
const translations = [
Expand Down Expand Up @@ -82,17 +83,21 @@ export default function Profile() {
const newNickname = nicknameRef.current.value;
const newStateMessage = stateMessageRef.current.value;

const res = await fetchUpdateUserState({
...userState,
nickname: newNickname,
stateMessage: newStateMessage,
});

if (res.message === 'done') {
setEditMode(!editMode);
await dispatch(updateNickname());
socketClient.current.emit('set userName', newNickname, userState.id);
navigate(`/profile/${newNickname}`, { replace: true });
if (!NICKNAME_REGEX.test(newNickname)) {
alert('λ‹‰λ„€μž„μ€ λ°˜λ“œμ‹œ ν•œκΈ€/영문(λŒ€μ†Œλ¬Έμž)/숫자둜만 μ΄λ£¨μ–΄μ Έμ•Όν•©λ‹ˆλ‹€.');
} else {
const res = await fetchUpdateUserState({
...userState,
nickname: newNickname,
stateMessage: newStateMessage,
});

if (res.message === 'done') {
setEditMode(!editMode);
await dispatch(updateNickname());
socketClient.current.emit('set userName', newNickname, userState.id);
navigate(`/profile/${newNickname}`, { replace: true });
}
}
} catch (error) {
console.log('error:', error);
Expand Down
19 changes: 12 additions & 7 deletions front-end/src/pages/RegisterPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useAppDispatch, useAppSelector } from '../../app/hooks';
import BasicButton from '../../components/BasicButton';
import BasicInput from '../../components/BasicInput';
import './style.scss';
import { NICKNAME_REGEX } from '../../constants';

function RegisterPage() {
const nickNameRef = useRef<HTMLInputElement>(null);
Expand Down Expand Up @@ -41,13 +42,17 @@ function RegisterPage() {
return;
}

dispatch(
registerNewUser({
nickname: nickNameRef.current.value,
message: messageRef.current?.value || '',
oauthInfo: user.profile.id,
})
);
if (!NICKNAME_REGEX.test(nickNameRef?.current?.value)) {
alert('λ‹‰λ„€μž„μ€ λ°˜λ“œμ‹œ ν•œκΈ€/영문(λŒ€μ†Œλ¬Έμž)/숫자둜만 μ΄λ£¨μ–΄μ Έμ•Όν•©λ‹ˆλ‹€.');
} else {
dispatch(
registerNewUser({
nickname: nickNameRef.current.value,
message: messageRef.current?.value || '',
oauthInfo: user.profile.id,
})
);
}
};

const onCancelClick = () => {
Expand Down