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

Auth/#62 #66

Merged
merged 13 commits into from
Apr 5, 2024
Merged

Auth/#62 #66

merged 13 commits into from
Apr 5, 2024

Conversation

seonghunYang
Copy link
Collaborator

@seonghunYang seonghunYang commented Apr 3, 2024

๐Ÿ“Œ ์ž‘์—… ๋‚ด์šฉ

๊ตฌํ˜„ ๋‚ด์šฉ ๋ฐ ์ž‘์—… ํ–ˆ๋˜ ๋‚ด์—ญ

  • ์ธ์ฆ ์ ˆ์ฐจ ๋กœ์ง์„ ๊ฐœ๋ฐœํ•˜๊ณ , ๋™์ž‘์„ ๊ฒ€์ฆํ•˜๊ธฐ ์œ„ํ•ด ๋ชจํ‚นํ–ˆ์Šต๋‹ˆ๋‹ค.
  • ์ธ์ฆ ์—ฌ๋ถ€์— ๋”ฐ๋ฅธ ํŽ˜์ด์ง€ ๋ผ์šฐํŒ…์„ ๋ฏธ๋“ค์›จ์–ด๋กœ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค.
  • ๋กœ๊ทธ์ธ ์„ฑ๊ณต ์‹œ ๋งˆ์ดํŽ˜์ด์ง€๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธํ•˜๋Š” ๊ธฐ๋Šฅ์œผ๋กœ ๋™์ž‘์„ ๋ณ€๊ฒฝํ–ˆ์Šต๋‹ˆ๋‹ค.

๐Ÿค” ๊ณ ๋ฏผ ํ–ˆ๋˜ ๋ถ€๋ถ„

  • ๊ฐœ๋ฐœํ•œ ๋ถ€๋ถ„์€ Next middleware์—์„œ ์ธ์ฆ ์—ฌ๋ถ€์— ๋”ฐ๋ฅธ ํŽ˜์ด์ง€ ๋ผ์šฐํŒ…์„ ํ•˜๋Š” ๋ถ€๋ถ„์ด๋ฏ€๋กœ, ํ…Œ์ŠคํŠธ ๋ฐฉ๋ฒ•์ด ์• ๋งคํ•˜์—ฌ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฐ ์ƒํ™ฉ์„ ํ…Œ์ŠคํŠธํ•˜๋ ค๋ฉด cypress์™€ ๊ฐ™์€ e2e ์ˆ˜์ค€์˜ ํ…Œ์ŠคํŠธ ๋„๊ตฌ๊ฐ€ ํ•„์š”ํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.
  • sign-in ์„ฑ๊ณต ์‹œ, useRouter๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ํ• ์ง€, redirect() ํ•จ์ˆ˜๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ํ• ์ง€ ๋‘ ๊ฐ€์ง€ ์„ ํƒ์ง€๊ฐ€ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. useRouter๋Š” ํด๋ผ์ด์–ธํŠธ ์‚ฌ์ด๋“œ์—์„œ ๋ผ์šฐํŒ…์ด๊ธฐ ๋•Œ๋ฌธ์— ์•„ํ‚คํ…์ฒ˜ ์ƒ์œผ๋กœ ๊ตณ์ด ํ•œ ๋‹จ๊ณ„๋ฅผ ๊ฑฐ์น  ํ•„์š”๊ฐ€ ์—†๋‹ค๊ณ  ํŒ๋‹จํ•˜์—ฌ redirect()๋ฅผ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.
  • fetch ์‹œ ํ† ํฐ์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ, ๋งค๋ฒˆ ๋ฐ˜๋ณต์ ์œผ๋กœ ํ—ค๋”์— ๋„ฃ์–ด์ค˜์•ผ ํ•˜๋Š” ๋ถˆํŽธํ•จ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ํ”„๋กœ์ ํŠธ ์ดˆ๋ฐ˜์— ๋…ผ์˜ํ–ˆ๋˜ fetch๋ฅผ wrappingํ•˜๋Š” ์ž‘์—…์ด ํ•„์š”ํ•˜๋ฉฐ, ๋งŒ์•ฝ ์ด ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•œ๋‹ค๋ฉด ์ง€๊ธˆ์ด ์ ์ ˆํ•œ ํƒ€์ด๋ฐ์ผ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. fetch wrapping ์‹œ์—๋Š” ํ—ค๋” ์„ค์ •๊ณผ ์—๋Ÿฌ ์ฒ˜๋ฆฌ ์„ค์ • ๊ธฐ๋Šฅ ๋“ฑ์ด ํ•„์š”ํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.
  • ์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ํ†ตํ•ด PDF ํŒŒ์ผ ์ œ์ถœ ์—ฌ๋ถ€๋ฅผ ํŒ๋‹จํ•ด์•ผ ํ•˜๋Š”๋ฐ, ์•„์ง API๊ฐ€ ๋ช…ํ™•ํžˆ ์ •์˜๋˜์ง€ ์•Š์•„ ์ž„์‹œ๋กœ ์ฒ˜๋ฆฌํ•˜์˜€์Šต๋‹ˆ๋‹ค. API๊ฐ€ ํ™•์ •๋˜๋ฉด ์ด๋ฅผ ์ˆ˜์ •ํ•  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.
  • ๊ฐœ๋ฐœ ํŽธ์˜์„ฑ์„ ์œ„ํ•ด, searchParam์— ?isAuth=true์ผ ๋•Œ๋งŒ ๋ฏธ๋“ค์›จ์–ด๊ฐ€ ์ž‘๋™ํ•˜๋„๋ก ์„ค์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. ํ•„์š”ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๊ณ , ๊ทธ ์™ธ์˜ ์‹œ๊ฐ„์—๋Š” ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„๋„ ๋ฉ๋‹ˆ๋‹ค.

๐Ÿ”Š ๋„์›€์ด ํ•„์š”ํ•œ ๋ถ€๋ถ„

Copy link

github-actions bot commented Apr 3, 2024

Copy link

github-actions bot commented Apr 3, 2024

Copy link
Member

@gahyuun gahyuun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค!

Comment on lines +43 to +46
// ๊ฐœ๋ฐœ์šฉ์ด์„ฑ์„ ์œ„ํ•ด isAuth=true ์ผ ๋•Œ๋งŒ ๋™์ž‘
if (isAuth === 'true') {
const auth = await getAuth(request);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ˜น์‹œ isAuth = true์˜ ์˜๋„์— ๋Œ€ํ•ด ์กฐ๊ธˆ ๋” ์„ค๋ช…ํ•ด์ฃผ์‹ค ์ˆ˜ ์žˆ๋‚˜์š”??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ๋ฏธ๋“ค์›จ์–ด์˜ ์—ญํ• ์€ ํ† ํฐ ๊ธฐ๋ฐ˜ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ์ˆ˜ํ–‰ํ•˜๊ณ , ๊ฒ€์‚ฌ๊ฐ€ ํ†ต๊ณผ๋œ ๊ฒฝ์šฐ์—๋งŒ ํ•ด๋‹น ํŽ˜์ด์ง€์— ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.
  • ๊ทธ๋Ÿฌ๋‚˜ ์ด ๊ฒฝ์šฐ, ์ธ์ฆ์ด ํ•„์š”ํ•œ ํŽ˜์ด์ง€ ๊ฐœ๋ฐœ์ด ๋ถˆํŽธํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ, ๊ฐœ๋ฐœ ๋‹จ๊ณ„์—์„œ๋Š” ํ•ด๋‹น ์กฐ๊ฑด๋ฌธ์œผ๋กœ ๋™์ž‘ํ•˜์ง€ ์•Š๋„๋ก ์„ค์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • ๋งŒ์•ฝ ์ธ์ฆ์— ๋”ฐ๋ฅธ ํŽ˜์ด์ง€ ๋ผ์šฐํŒ… ๋™์ž‘์ด ํ•„์š”ํ•˜๋‹ค๋ฉด, isAuth=true๋กœ searchParam์„ ์„ค์ •ํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

};
}

const validatedResult = await validateToken();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accessToken์ด ์กด์žฌํ•˜๋ฉด validateToken ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋„ค์š”!
accessToken์ด ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ๋งˆ๋‹ค ์ƒˆ๋กœ ํ† ํฐ์„ ์žฌ๋ฐœ๊ธ‰ํ•˜์—ฌ ์š”์ฒญ์„ ๋ณด๋‚ด๋Š” ํ”Œ๋กœ์šฐ ๊ฐ™์€๋ฐ, ์ด ์ด์œ ๊ฐ€ ์žˆ๋‚˜์šฉ??
์ €๋Š” accessToken์ด ์กด์žฌํ•˜๋ฉด ํ•ด๋‹น accessToken์œผ๋กœ ์š”์ฒญ์„ ๋ณด๋‚ด๊ณ , error ์‘๋‹ต์‹œ ํ† ํฐ ์žฌ๋ฐœ๊ธ‰ ํ›„ ์žฌ์š”์ฒญ ์ด ํ”Œ๋กœ์šฐ๋ฅผ ์ƒ๊ฐํ–ˆ์–ด์„œ ์—ฌ์ญค๋ด…๋‹ˆ๋‹ค!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ๋ง์”€ํ•˜์‹ ๋Œ€๋กœ ์ผ๋ฐ˜ fetch ์š”์ฒญ์˜ ๊ฒฝ์šฐ ๊ทธ๋ ‡๊ฒŒ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์‹ค์ œ๋กœ, ํด๋ผ์ด์–ธํŠธ ์‚ฌ์ด๋“œ์—์„œ ์ธ์ฆ์ด ์‹คํŒจํ•˜๋ฉด(401 ์—๋Ÿฌ ๋ฐœ์ƒ ์‹œ) ์—๋Ÿฌ ๋ฐ”์šด๋”๋ฆฌ์—์„œ ์ด๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๋กœ์ง์„ ๋‹ค์Œ ์ž‘์—…์œผ๋กœ ๊ฐœ๋ฐœํ•  ๊ณ„ํš์ž…๋‹ˆ๋‹ค.
  • ๊ทธ๋Ÿฌ๋‚˜ ์ด ๊ฒฝ์šฐ๋Š” ํŽ˜์ด์ง€ ๋ผ์šฐํŒ…์— ๋Œ€ํ•œ ๊ถŒํ•œ ์ธ์ฆ์ด๋ฉฐ, ํ˜„์žฌ Next์™€ API ์„œ๋ฒ„๋ฅผ ๋ถ„๋ฆฌํ•˜๊ณ  ์žˆ๋Š” ์ €ํฌ ์•„ํ‚คํ…์ฒ˜ ๊ตฌ์กฐ์ƒ, ํ•ด๋‹น ํŽ˜์ด์ง€์— ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•œ์ง€ ๊ฒ€์‚ฌํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ํ•ด๋‹น ํ† ํฐ์ด ์œ ํšจํ•œ์ง€๋ฅผ ๊ฒ€์‚ฌํ•  ์ˆ˜๋ฐ–์— ์—†์Šต๋‹ˆ๋‹ค.
  • ์ด์œ ๋Š” Next ์„œ๋ฒ„์™€ API ์„œ๋ฒ„๊ฐ€ ๋ถ„๋ฆฌ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. SSR์„ ์œ„ํ•œ Next ์„œ๋ฒ„์—๋Š” ์ธ์ฆ ์ •๋ณด๊ฐ€ ์—†์œผ๋ฏ€๋กœ, API ์„œ๋ฒ„์—์„œ ์ด ์š”์ฒญ์ด ์œ ํšจํ•œ์ง€ ํ™•์ธํ•œ ํ›„์— ๋ผ์šฐํŒ…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋„ต ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค!

studentNumber: z.string(),
studentName: z.string(),
major: z.string(),
isSumbitted: z.boolean(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์–ด์ œ ํšŒ์˜์— ์˜ํ•˜๋ฉด isSumbittedํ•ด๋‹น ์ปฌ๋Ÿผ์€ ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ์•ˆ๋‚ด๋ ค์˜ค๋Š” ๊ฒƒ ์•„๋‹Œ๊ฐ€์š”?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ํ˜„์žฌ ํ•ด๋‹น API์— ๋Œ€ํ•œ ๋ช…์„ธ๊ฐ€ ์ •ํ™•ํ•˜๊ฒŒ ๋˜์–ด ์žˆ์ง€ ์•Š์•„์„œ ์ผ๋‹จ ์ž„์˜๋กœ ์ฒ˜๋ฆฌํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • ์ถ”ํ›„ ๋ช…์„ธ๊ฐ€ ํ™•์ •๋˜๋ฉด ๋ณ€๊ฒฝํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

@seonghunYang seonghunYang merged commit da0c9fc into main Apr 5, 2024
3 checks passed
@seonghunYang seonghunYang deleted the auth/#62 branch April 5, 2024 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants