Page 411 - Nodejs 교과서 개정2판
P. 411

}	else	{
           				const	message	=	encodeURIComponent('로그인한	상태입니다.');
           				res.redirect(`/?error=${message}`);
           		}
           };




         1BTTQPSUח req ё୓ী isAuthenticated ݫࢲ٘ܳ ୶о೤פ׮  ۽Ӓੋ ઺੉ݶ req.isAuthenticated()о tru

         eҊ  Ӓۧ૑ ঋਵݶ falseੑפ׮  ٮۄࢲ ۽Ӓੋ ৈࠗܳ ੉ ݫࢲ٘۽ ౵ঈೡ ࣻ ੓णפ׮  ۄ਋ఠٜ ઺ী ۽Ӓই
         ਓ ۄ਋ఠա ੉޷૑ স۽٘ ۄ਋ఠ ١਷ ۽Ӓੋೠ ࢎۈ݅ ੽Ӕೡ ࣻ ੓ѱ ೧ঠ ೞҊ  ഥਗоੑ ۄ਋ఠա ۽Ӓੋ
         ۄ਋ఠח ۽Ӓੋೞ૑ ঋ਷ ࢎۈ݅ ੽Ӕೡ ࣻ ੓ѱ ೧ঠ ೤פ׮  ੉ۡ ٸ ۄ਋ఠী ۽Ӓੋ ৈࠗܳ Ѩࢎೞח ޷ٜ

         ਝযܳ ֍য Ѧ۞յ ࣻ ੓णפ׮

         isLoggedInҗ isNotLoggedIn ޷ٜਝযܳ ٜ݅঻णפ׮  ੉ ޷ٜਝযٜ੉ page ۄ਋ఠী যڌѱ ࢎਊغח૑ ࠇ

         द׮

          routes/page.js

           const	express	=	require('express');
           const	{	isLoggedIn,	isNotLoggedIn	}	=	require('./middlewares');


           const	router	=	express.Router();
           router.use((req,	res,	next)	=>	{
           		res.locals.user	=	req.user;
           		res.locals.followerCount	=	0;
           		res.locals.followingCount	=	0;
           		res.locals.followerIdList	=	[];
           		next();
           });


           router.get('/profile',	isLoggedIn,	(req,	res)	=>	{
           		res.render('profile',	{	title:	'내	정보	-	NodeBird'	});
           });


           router.get('/join',	isNotLoggedIn,	(req,	res)	=>	{
           		res.render('join',	{	title:	'회원가입	-	NodeBird'	});
           });
           ...




         ੗न੄ ೐۽೙਷ ۽Ӓੋਸ ೧ঠ ࠅ ࣻ ੓ਵ޲۽ isLoggedIn ޷ٜਝযܳ ࢎਊ೤פ׮  req.isAuthenticated()о

         trueৈঠ nextо ഐ୹غয SFT SFOEFSо ੓ח ޷ٜਝয۽ ֈযт ࣻ ੓णפ׮  falseۄݶ ۽Ӓੋ ହ੉ ੓ח ݫ
         ੋ ಕ੉૑۽ ܻ׮੉۩౟ؾפ׮
   406   407   408   409   410   411   412   413   414   415   416