๐ Today I Learned
- JWT๋ฅผ ์ฌ์ฉํ์ฌ ๋ณธ์ธ์ธ์ฆ์ด ํ์ํ API๋ค ์์ ํ๊ธฐ
- JWT payload๋ถ๋ถ์ userIdx๋ฅผ ๋ฃ์ด ํ ํฐ ๋ฐ๊ธ
- ๋ฐ๊ธ๋ ํ ํฐ์ ์ด์ฉํ์ฌ ์์ ์ญ์ API๋ฅผ ๋ก๊ทธ์ธํด์ผ ์คํ์ด ๊ฐ๋ฅํ๋๋ก ์์
- ex) ์์ ์ญ์ API, ํ๋กํ ์์ API
๐ข Today's error
Error 1
![0825-1](https://user-images.githubusercontent.com/77181984/130852110-7e53c9ce-f203-41d5-af3b-98bff86335a6.png)
const passwordRows = await userProvider.passwordCheck(selectUserPasswordParams);
console.log(passwordRows);
if (passwordRows[0].Password !== hashedPassword) {
return errResponse(baseResponse.SIGNIN_PASSWORD_WRONG);
}
- userProvider.passwordCheck์์ ๋ฐ์์จ passwordRows์ธ๋ฐ, ๋ด๊ฐ ์ฌ์ฉํ๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๋ณ์๋ช userPassword๊ฐ ์๋ password๋ก ์์ฑํด์ ๋ฐ์ํ ์๋ฌ์ด๋ค.
Error 2
![0825-2์ฐ](https://user-images.githubusercontent.com/77181984/130852123-56ba578b-c4e7-4369-b20b-e69c312d236d.png)
let token = await jwt.sign(
{
userIdx : userInfoRows[0].userIdx,
}, // payload
secret_config.jwtsecret, // ๋น๋ฐํค
{
expiresIn: "365d",
subject: "userLogin",
} // ์ ํจ ๊ธฐ๊ฐ 365์ผ
);
return response(baseResponse.SUCCESS, {'userIdx': userInfoRows[0].**userIdx**, 'jwt': token});
- ๋ง์ฐฌ๊ฐ์ง๋ก userInfoRows[0].userIdx ๋ถ๋ถ์ userInfoRows[0].id, userInfoRows[0].userId ์ด๋ ๊ฒ ์์ฑํ์ฌ ๋ฐ์ํ ์๋ฌ์ด๋ค.
- userInfoRows[0]. ๊น์ง ์ณค์ ๋ ๋์ค๋ ๋ณ์๋ช
๋ค์ ํนํด์ ๊ณ ์ํ๋ค..
๊ผญ ๋ด๊ฐ ์ฟผ๋ฆฌ์์ ๋ฝ์์จ ๋ณ์๋ช ์ผ๋ก ํ ํฐ์ ๋ฐ๊ธํ์.
![0824-3](https://user-images.githubusercontent.com/77181984/130852134-5be50246-1b42-4032-af4b-f0304d6f1072.png)
- userIdx ํ ํฐ ์์ฑ ์ฑ๊ณต !
๐ Comment
์๋ง์ ์๋ฌ๋ฅผ ์ฒ๋ฆฌํ๋ ๊ณผ์ ์ ์๊ฐ์ ๋๋ฌด ๋ง์ด ์ฐ๋ ๊ฒ ๊ฐ์์, ๊ฐ์ ์ค์๋ฅผ ๋ฐ๋ณตํ์ง ์๊ธฐ ์ํด TIL์ ์์ฑํ๊ธฐ๋ก ํ๋ค. ์ค๋๋ ํ๋ฃจ์ข ์ผ ์์์ API๋ค์ ์ ๊ฒํ๋๋ฐ, ์ถ๊ฐํ ์ฝ๋๋ 10์ค๋ ๋์ง ์์๋ค..๐ญ
'TIL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[TIL] 2021-08-29 (1) | 2021.08.30 |
---|---|
[TIL] 2021-08-27 (0) | 2021.08.28 |
[TIL] 2021-08-26 (2) | 2021.08.27 |