Daily/Today I Learned

210307_TIL (MVC, ์ฟ ํ‚ค/์„ธ์…˜ ์Šคํ”„๋ฆฐํŠธ ๋ณต์Šต)

joooing 2021. 3. 8. 19:32
๋ฐ˜์‘ํ˜•

๐ŸŽ ์˜ค๋Š˜ ํ•œ ์ผ


MVC, ์ฟ ํ‚ค, ์„ธ์…˜ ๋ณต์Šต 
๋‹ค์‹œ ํŒŒ์ผ์„ ๋ฐ›์•„์„œ MVC, Cookie, Session ์Šคํ”„๋ฆฐํŠธ๋ฅผ ํ’€์–ด๋ดค๋‹ค. ์ „์—๋Š” ๊ทธ๋ ‡๊ฒ ์ง€ํ•˜๊ณ  ๋„˜๊ฒผ๋˜ ๋ถ€๋ถ„๋“ค์ด ์ค‘๊ฐ„์ค‘๊ฐ„ ์žˆ์–ด์„œ ๊ทธ ๋ถ€๋ถ„๋“ค์„ ๋‹ค์‹œ ์ž์„ธํžˆ ์ฐพ์•„๋ณด๋ฉฐ ํ•œ๋ฒˆ์”ฉ ์ œ๋Œ€๋กœ ์งš๊ณ  ๋„˜์–ด๊ฐˆ ์ˆ˜ ์žˆ์—ˆ๋‹ค. ํŠนํžˆ Session ๋ถ€๋ถ„์—์„œ express์˜ ์„ธ์…˜ ๊ด€๋ฆฌ์šฉ ๋ฏธ๋“ค์›จ์–ด์ธ express-session์— ๋Œ€ํ•ด ์ข€ ๋” ์•Œ์•„๋ดค๋‹ค. save ๋ฉ”์„œ๋“œ ์—†์ด ํ–ˆ๋Š”๋ฐ๋„ ์ž˜ ์ž‘๋™ํ–ˆ๋Š”๋ฐ, ๋ ˆํผ๋Ÿฐ์Šค์—์„œ๋Š” ์ผ๊ธธ๋ž˜, ์™œ์ธ์ง€ ์ฐพ์•„๋ดค๋”๋‹ˆ ๊ณต์‹๋ฌธ์„œ์— "This method is automatically called at the end of the HTTP response if the session data has been altered" ๋ผ๊ณ  ๋‚˜์™€์žˆ์—ˆ๋‹ค. ์ž๋™์œผ๋กœ ํ˜ธ์ถœ๋˜์–ด์„œ ์ƒ๊ด€์ด์—†๋˜๊ฑฐ์˜€๋‹ค.. ๊ทธ๋ž˜๋„ ์ž‘๋™ ์ˆœ์„œ์— ์ฃผ์˜ํ•ด์•ผํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์–ด์„œ save๋Š” ์ตœ๋Œ€ํ•œ ์จ์ฃผ๋Š”๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™๋‹ค.

 

๐ŸŽ ๊ธฐ์–ตํ•  ๊ฒƒ


express-session
express-session์€ req ๊ฐ์ฒด์•ˆ์— req.session ๊ฐ์ฒด๋ฅผ ๋งŒ๋“œ๋Š”๋ฐ, ๊ฐ’์„ ๋Œ€์ž…ํ•˜๊ฑฐ๋‚˜ ์‚ญ์ œํ•ด์„œ ์„ธ์…˜์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‚˜์ค‘์— ์„ธ์…˜์„ ํ•œ๋ฒˆ์— ์‚ญ์ œํ•˜๋ ค๋ฉด req.session.destroy() ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ๋œ๋‹ค. ํ˜„์žฌ ์„ธ์…˜์˜ ์•„์ด๋””๋Š” req.sesstionId๋กœ ํ™•์ธํ•  ์ˆ˜์žˆ๋‹ค!

 

๐ŸŽ ๋” ๊ณต๋ถ€ํ•  ๊ฒƒ


โœ”๏ธ OAuth
๋ฐ˜์‘ํ˜•