{"id":41112,"date":"2024-11-06T02:46:37","date_gmt":"2024-11-06T02:46:37","guid":{"rendered":"https:\/\/atmokpo.com\/w\/?p=41112"},"modified":"2024-11-26T06:37:33","modified_gmt":"2024-11-26T06:37:33","slug":"19-nest-js%ec%99%80-next-js%ec%97%90%ec%84%9c-middleware%ec%99%80-guard-%ec%82%ac%ec%9a%a9%ed%95%98%ea%b8%b0-nest-js%ec%97%90%ec%84%9c-%eb%af%b8%eb%93%a4%ec%9b%a8%ec%96%b4%ec%99%80-%ea%b0%80%eb%93%9c","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/41112\/","title":{"rendered":"19.Nest.js\uc640 Next.js\uc5d0\uc11c Middleware\uc640 Guard \uc0ac\uc6a9\ud558\uae30, Nest.js\uc5d0\uc11c \ubbf8\ub4e4\uc6e8\uc5b4\uc640 \uac00\ub4dc\ub85c \uc778\uc99d \ubc0f \uad8c\ud55c \uc81c\uc5b4\ud558\uae30"},"content":{"rendered":"<p><body><\/p>\n<p>Nest.js\uc640 Next.js\ub294 \ud604\ub300\uc758 \uc6f9 \uc560\ud50c\ub9ac\ucf00\uc774\uc158 \uac1c\ubc1c\uc5d0 \uc788\uc5b4 \uac15\ub825\ud55c \ud504\ub808\uc784\uc6cc\ud06c\uc785\ub2c8\ub2e4. \uc774 \ub450 \ud504\ub808\uc784\uc6cc\ud06c\ub294 \uc27d\uac8c \uc2a4\ucf00\uc77c\ub9c1 \uac00\ub2a5\ud55c \uc560\ud50c\ub9ac\ucf00\uc774\uc158 \uc544\ud0a4\ud14d\ucc98\ub97c \uc81c\uacf5\ud569\ub2c8\ub2e4. \ubcf8 \uac15\uc88c\uc5d0\uc11c\ub294 Nest.js\uc640 Next.js\uc5d0\uc11c \uac01\uac01 Middleware\uc640 Guard\ub97c \uc0ac\uc6a9\ud558\uc5ec \uc778\uc99d \ubc0f \uad8c\ud55c \uc81c\uc5b4\ub97c \uad6c\ud604\ud558\ub294 \ubc29\ubc95\uc5d0 \ub300\ud574 \uc790\uc138\ud788 \uc124\uba85\ud558\uaca0\uc2b5\ub2c8\ub2e4.<\/p>\n<h2>1. Middleware\ub780?<\/h2>\n<p>Middleware\ub294 \ub450 \uac1c\uc758 \ud568\uc218 \uac04\uc5d0 \uc2e4\ud589\ub418\ub294 \ucf54\ub4dc\ub85c, \uc8fc\ub85c \uc694\uccad(Request)\uacfc \uc751\ub2f5(Response) \uac1d\uccb4\uc5d0 \ub300\ud55c \ucc98\ub9ac\ub97c \uc218\ud589\ud558\ub294 \ub370 \uc0ac\uc6a9\ub429\ub2c8\ub2e4. \uc608\ub97c \ub4e4\uc5b4, \uc694\uccad\uc744 \ub85c\uae45\ud558\uac70\ub098 \uc694\uccad\uc744 \uc218\uc815\ud558\uac70\ub098 \uc0ac\uc6a9\uc790\ub97c \uc778\uc99d\ud558\ub294 \ub370 \uc0ac\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. Nest.js\uc5d0\uc11c\ub294 \ubbf8\ub4e4\uc6e8\uc5b4\ub97c \uc0ac\uc6a9\ud558\uc5ec \uc694\uccad\uc744 \uac00\ub85c\ucc44\uace0 \uc5b4\ub5a4 \uc791\uc5c5\uc744 \uc218\ud589\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<h3>Middleware\uc758 \ud2b9\uc9d5<\/h3>\n<ul>\n<li>\uc694\uccad\uc744 \uac00\ub85c\ucc4c \uc218 \uc788\ub2e4.<\/li>\n<li>\uc751\ub2f5\uc744 \uc218\uc815\ud560 \uc218 \uc788\ub2e4.<\/li>\n<li>\ube44\uc988\ub2c8\uc2a4 \ub85c\uc9c1\uacfc \ub370\uc774\ud130\ubca0\uc774\uc2a4 \uc811\uadfc\uc744 \ud560 \uc218 \uc788\ub2e4.<\/li>\n<\/ul>\n<h2>2. Nest.js\uc5d0\uc11c Middleware \uad6c\ud604\ud558\uae30<\/h2>\n<p>Nest.js\uc5d0\uc11c\ub294 \ubbf8\ub4e4\uc6e8\uc5b4\ub97c \ub9cc\ub4e4\uae30 \uc704\ud574 \uae30\ubcf8\uc801\uc73c\ub85c <code>MiddlewareConsumer<\/code>\ub97c \uc0ac\uc6a9\ud569\ub2c8\ub2e4. \ubbf8\ub4e4\uc6e8\uc5b4\ub294 \ud074\ub798\uc2a4 \uae30\ubc18\uc73c\ub85c \ub9cc\ub4e4 \uc218 \uc788\uc73c\uba70, <code>@Injectable()<\/code> \ub370\ucf54\ub808\uc774\ud130\ub97c \uc0ac\uc6a9\ud558\uc5ec \uc758\uc874\uc131\uc744 \uc8fc\uc785\ubc1b\uc744 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<h3>\uc608\uc81c: \uc778\uc99d \ubbf8\ub4e4\uc6e8\uc5b4 \uad6c\ud604\ud558\uae30<\/h3>\n<pre><code>import { Injectable, NestMiddleware } from '@nestjs\/common';\nimport { Request, Response, NextFunction } from 'express';\n\n@Injectable()\nexport class AuthMiddleware implements NestMiddleware {\n    use(req: Request, res: Response, next: NextFunction) {\n        const token = req.headers['authorization'];\n\n        if (token) {\n            \/\/ \ud1a0\ud070 \uac80\uc99d \ub85c\uc9c1\n            next();\n        } else {\n            res.status(403).send('Forbidden');\n        }\n    }\n}\n<\/code><\/pre>\n<p>\uc704 \ucf54\ub4dc\uc5d0\uc11c <code>AuthMiddleware<\/code>\ub294 \uc0ac\uc6a9\uc790\uc758 \uc694\uccad\uc5d0\uc11c Authorization \ud5e4\ub354\ub97c \ud655\uc778\ud558\uace0, \ud1a0\ud070\uc774 \uc720\ud6a8\ud55c\uc9c0 \uac80\uc0ac\ud569\ub2c8\ub2e4. \uc720\ud6a8\ud55c \uacbd\uc6b0 <code>next()<\/code>\ub97c \ud638\ucd9c\ud558\uc5ec \ub2e4\uc74c \ubbf8\ub4e4\uc6e8\uc5b4\ub85c \uc9c4\ud589\ud558\uace0, \uadf8\ub807\uc9c0 \uc54a\uc73c\uba74 403 Forbidden \uc5d0\ub7ec\ub97c \ubc18\ud658\ud569\ub2c8\ub2e4.<\/p>\n<h3>Middleware \ub4f1\ub85d\ud558\uae30<\/h3>\n<pre><code>import { Module, MiddlewareConsumer } from '@nestjs\/common';\nimport { AuthMiddleware } from '.\/auth.middleware';\n\n@Module({\n    \/\/ \ubaa8\ub4c8 \uc124\uc815\n})\nexport class AppModule {\n    configure(consumer: MiddlewareConsumer) {\n        consumer\n            .apply(AuthMiddleware)\n            .forRoutes('*'); \/\/ \ubaa8\ub4e0 \ub77c\uc6b0\ud2b8\uc5d0 \uc801\uc6a9\n    }\n}\n<\/code><\/pre>\n<h2>3. Guard\ub780?<\/h2>\n<p>Guard\ub294 \uc694\uccad\uc774 \ub77c\uc6b0\ud130 \ud578\ub4e4\ub7ec\uc5d0 \ub3c4\ub2ec\ud558\uae30 \uc804\uc5d0 \ud2b9\uc815 \uc870\uac74\uc744 \ud3c9\uac00\ud558\uc5ec \uc694\uccad\uc744 \ucc28\ub2e8\ud560 \uc218 \uc788\ub294 \uba54\ucee4\ub2c8\uc998\uc785\ub2c8\ub2e4. \uc608\ub97c \ub4e4\uc5b4, \uc0ac\uc6a9\uc790\uac00 \ud2b9\uc815 \uc0ac\uc6a9\uc790 \uc5ed\ud560\uc774\ub098 \uad8c\ud55c\uc744 \uac00\uc9c0\uace0 \uc788\ub294\uc9c0 \uac80\uc99d\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<h3>Guard\uc758 \ud2b9\uc9d5<\/h3>\n<ul>\n<li>\uc694\uccad \ucc98\ub9ac \uc5ec\ubd80\ub97c \uacb0\uc815\ud560 \uc218 \uc788\ub2e4.<\/li>\n<li>\ud2b9\uc815 \uc870\uac74\uc5d0 \ub530\ub77c \uc694\uccad\uc744 \ud5c8\uc6a9\ud558\uac70\ub098 \uac70\ubd80\ud55c\ub2e4.<\/li>\n<\/ul>\n<h2>4. Nest.js\uc5d0\uc11c Guard \uad6c\ud604\ud558\uae30<\/h2>\n<p>Guard\ub294 <code>CanActivate<\/code> \uc778\ud130\ud398\uc774\uc2a4\ub97c \uad6c\ud604\ud558\uc5ec \uc0dd\uc131\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc8fc\ub85c \uc0ac\uc6a9\uc790\uc758 \uad8c\ud55c\uc744 \uccb4\ud06c\ud558\uac70\ub098 \uc778\uc99d \uc5ec\ubd80\ub97c \ud655\uc778\ud558\ub294 \ub370 \ud65c\uc6a9\ub429\ub2c8\ub2e4.<\/p>\n<h3>\uc608\uc81c: Role Guard \uad6c\ud604\ud558\uae30<\/h3>\n<pre><code>import { Injectable, CanActivate, ExecutionContext } from '@nestjs\/common';\n\n@Injectable()\nexport class RoleGuard implements CanActivate {\n    canActivate(context: ExecutionContext): boolean {\n        const request = context.switchToHttp().getRequest();\n        const user = request.user;\n\n        \/\/ \uc0ac\uc6a9\uc790 \uc5ed\ud560 \ud655\uc778 \ub85c\uc9c1\n        return user &amp;&amp; user.role === 'admin';\n    }\n}\n<\/code><\/pre>\n<h3>Guard \ub4f1\ub85d\ud558\uae30<\/h3>\n<pre><code>import { Controller, Get, UseGuards } from '@nestjs\/common';\nimport { RoleGuard } from '.\/role.guard';\n\n@Controller('admin')\nexport class AdminController {\n    @Get()\n    @UseGuards(RoleGuard)\n    getAdminData() {\n        return 'Admin data!';\n    }\n}\n<\/code><\/pre>\n<h2>5. Next.js\uc5d0\uc11c Middleware \uc0ac\uc6a9\ud558\uae30<\/h2>\n<p>Next.js\ub294 \uc804\ud1b5\uc801\uc778 \ub77c\uc6b0\ud130 \ubc29\uc2dd\uc744 \uc0cc\ub4dc\uc704\uce58\ucc98\ub7fc \ub808\uc774\uc5b4\ub9c1\ud55c \ud615\ud0dc\uc758 \uc544\ud0a4\ud14d\ucc98\ub97c \uac00\uc9c0\uace0 \uc788\uc2b5\ub2c8\ub2e4. Middleware\ub294 \uc694\uccad\uc774 \ud2b9\uc815 API \ub77c\uc6b0\ud305 \uacbd\ub85c\uc5d0 \ub3c4\ub2ec\ud558\uae30 \uc804\uc5d0 \uc0ac\uc6a9\ub418\ub294 \ud568\uc218\ub85c, \uc778\uc99d, \uad8c\ud55c \ub4f1 \ub2e4\uc591\ud55c \ub85c\uc9c1\uc744 \ucc98\ub9ac\ud558\ub294 \ub370 \uc0ac\uc6a9\ub420 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<h3>\uc608\uc81c: Next.js\uc5d0\uc11c \ubbf8\ub4e4\uc6e8\uc5b4 \uad6c\ud604\ud558\uae30<\/h3>\n<pre><code>import { NextResponse } from 'next\/server';\n\nexport function middleware(req) {\n    const token = req.headers.get('authorization');\n\n    if (token) {\n        \/\/ \ud1a0\ud070 \uac80\uc99d \ub85c\uc9c1\n        return NextResponse.next();\n    } else {\n        return NextResponse.redirect('\/login');\n    }\n}\n<\/code><\/pre>\n<h3>Middleware \ub4f1\ub85d\ud558\uae30<\/h3>\n<p>Next.js\uc5d0\uc11c\ub294 Middleware\ub97c \uc804\uccb4 \uc560\ud50c\ub9ac\ucf00\uc774\uc158\uc774\ub098 \ud2b9\uc815 \uacbd\ub85c\uc5d0 \uc801\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. <code>middleware.ts<\/code> \ud30c\uc77c\uc744 \ub8e8\ud2b8\uc5d0 \uc0dd\uc131\ud558\uace0, \uadf8 \ub0b4\ubd80\uc5d0 \ubbf8\ub4e4\uc6e8\uc5b4 \ub85c\uc9c1\uc744 \uc815\uc758\ud558\uba74 \ub429\ub2c8\ub2e4.<\/p>\n<h2>6. Next.js\uc5d0\uc11c Guard \uc0ac\uc6a9\ud558\uae30<\/h2>\n<p>Next.js\uc5d0\uc11c\ub294 Guard\ub97c \uba85\uc2dc\uc801\uc73c\ub85c \uad6c\ud604\ud558\ub294 \uac83\uc774 \uc544\ub2c8\ub77c, \ub0b4\ubd80 \ucef4\ud3ec\ub10c\ud2b8\uc5d0\uc11c \uc870\uac74\ubd80 \ub80c\ub354\ub9c1\uc744 \ud1b5\ud574 \uc778\uc99d \ubc0f \uad8c\ud55c \uc81c\uc5b4\ub97c \uc218\ud589\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc608\ub97c \ub4e4\uc5b4, API \uc694\uccad\uc744 \ud1b5\ud574 \uc0ac\uc6a9\uc790 \uc815\ubcf4\ub97c \uac00\uc838\uc624\uace0, \uc774\ub97c \uae30\ubc18\uc73c\ub85c \ucef4\ud3ec\ub10c\ud2b8\ub97c \uc870\uac74\ubd80\ub85c \ub80c\ub354\ub9c1\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<h3>\uc608\uc81c: Hook\uc744 \uc0ac\uc6a9\ud55c Role Guard \uad6c\ud604\ud558\uae30<\/h3>\n<pre><code>import { useEffect, useState } from 'react';\n\nfunction useAuth(requiredRole) {\n    const [user, setUser] = useState(null);\n\n    useEffect(() =&gt; {\n        const getUserData = async () =&gt; {\n            const res = await fetch('\/api\/user');\n            const data = await res.json();\n            setUser(data);\n        };\n\n        getUserData();\n    }, []);\n\n    return user &amp;&amp; user.role === requiredRole;\n}\n\n\/\/ \uc0ac\uc6a9 \uc608\uc2dc\nfunction AdminPage() {\n    const isAdmin = useAuth('admin');\n\n    if (!isAdmin) {\n        return <p>Access Denied<\/p>;\n    }\n\n    return <h1>Admin Page<\/h1>;\n}\n<\/code><\/pre>\n<h2>7. \uacb0\ub860<\/h2>\n<p>Nest.js\uc640 Next.js \ubaa8\ub450\uc5d0\uc11c Middleware\uc640 Guard\ub97c \ud65c\uc6a9\ud558\uba74 \uc560\ud50c\ub9ac\ucf00\uc774\uc158\uc758 \uc778\uc99d \ubc0f \uad8c\ud55c \uc81c\uc5b4\ub97c \ud6a8\uc728\uc801\uc73c\ub85c \uad00\ub9ac\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. Nest.js\uc5d0\uc11c\ub294 \ubbf8\ub4e4\uc6e8\uc5b4\uc640 \uac00\ub4dc\ub97c \ud074\ub798\uc2a4\ub85c \uc815\uc758\ud558\uace0 \uc0ac\uc6a9\ud560 \uc218 \uc788\uc73c\uba70, Next.js\uc5d0\uc11c\ub294 \ubbf8\ub4e4\uc6e8\uc5b4\ub97c \ud1b5\ud574 \uc694\uccad \ucc98\ub9ac\ub97c \uc6b0\uc120\uc801\uc73c\ub85c \uc218\ud589\ud558\uace0, \uc870\uac74\ubd80 \ub80c\ub354\ub9c1\uc774\ub098 Hook\uc744 \uc0ac\uc6a9\ud558\uc5ec \uad8c\ud55c \uc81c\uc5b4\ub97c \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<div class=\"note\">\n<strong>Note:<\/strong> \uac01 \ud504\ub808\uc784\uc6cc\ud06c\uc758 \uc0dd\ud0dc\uacc4\uc640 \uae30\ub2a5\uc740 \uc9c0\uc18d\uc801\uc73c\ub85c \ubc1c\uc804\ud558\uace0 \uc788\uc73c\ubbc0\ub85c, \ud56d\uc0c1 \ucd5c\uc2e0 \ubb38\uc11c\ub97c \ucc38\uc870\ud558\uc5ec \uad6c\ud604\ud558\ub294 \uac83\uc774 \uc88b\uc2b5\ub2c8\ub2e4.\n    <\/div>\n<p>\ub354 \ub9ce\uc740 \uc815\ubcf4\uc640 \uc608\uc81c\ub294 \uacf5\uc2dd \ubb38\uc11c\ub97c \ucc38\uace0\ud558\uc2dc\uae30 \ubc14\ub78d\ub2c8\ub2e4.<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.nestjs.com\/middleware\">Nest.js Middleware Documentation<\/a><\/li>\n<li><a href=\"https:\/\/docs.nestjs.com\/guards\">Nest.js Guards Documentation<\/a><\/li>\n<li><a href=\"https:\/\/nextjs.org\/docs\/middleware\">Next.js Middleware Documentation<\/a><\/li>\n<\/ul>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nest.js\uc640 Next.js\ub294 \ud604\ub300\uc758 \uc6f9 \uc560\ud50c\ub9ac\ucf00\uc774\uc158 \uac1c\ubc1c\uc5d0 \uc788\uc5b4 \uac15\ub825\ud55c \ud504\ub808\uc784\uc6cc\ud06c\uc785\ub2c8\ub2e4. \uc774 \ub450 \ud504\ub808\uc784\uc6cc\ud06c\ub294 \uc27d\uac8c \uc2a4\ucf00\uc77c\ub9c1 \uac00\ub2a5\ud55c \uc560\ud50c\ub9ac\ucf00\uc774\uc158 \uc544\ud0a4\ud14d\ucc98\ub97c \uc81c\uacf5\ud569\ub2c8\ub2e4. \ubcf8 \uac15\uc88c\uc5d0\uc11c\ub294 Nest.js\uc640 Next.js\uc5d0\uc11c \uac01\uac01 Middleware\uc640 Guard\ub97c \uc0ac\uc6a9\ud558\uc5ec \uc778\uc99d \ubc0f \uad8c\ud55c \uc81c\uc5b4\ub97c \uad6c\ud604\ud558\ub294 \ubc29\ubc95\uc5d0 \ub300\ud574 \uc790\uc138\ud788 \uc124\uba85\ud558\uaca0\uc2b5\ub2c8\ub2e4. 1. Middleware\ub780? Middleware\ub294 \ub450 \uac1c\uc758 \ud568\uc218 \uac04\uc5d0 \uc2e4\ud589\ub418\ub294 \ucf54\ub4dc\ub85c, \uc8fc\ub85c \uc694\uccad(Request)\uacfc \uc751\ub2f5(Response) \uac1d\uccb4\uc5d0 \ub300\ud55c \ucc98\ub9ac\ub97c \uc218\ud589\ud558\ub294 \ub370 \uc0ac\uc6a9\ub429\ub2c8\ub2e4. \uc608\ub97c \ub4e4\uc5b4, &hellip; <a href=\"https:\/\/atmokpo.com\/w\/41112\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;19.Nest.js\uc640 Next.js\uc5d0\uc11c Middleware\uc640 Guard \uc0ac\uc6a9\ud558\uae30, Nest.js\uc5d0\uc11c \ubbf8\ub4e4\uc6e8\uc5b4\uc640 \uac00\ub4dc\ub85c \uc778\uc99d \ubc0f \uad8c\ud55c \uc81c\uc5b4\ud558\uae30&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[223],"tags":[],"class_list":["post-41112","post","type-post","status-publish","format-standard","hentry","category-nextjs"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>19.Nest.js\uc640 Next.js\uc5d0\uc11c Middleware\uc640 Guard \uc0ac\uc6a9\ud558\uae30, Nest.js\uc5d0\uc11c \ubbf8\ub4e4\uc6e8\uc5b4\uc640 \uac00\ub4dc\ub85c \uc778\uc99d \ubc0f \uad8c\ud55c \uc81c\uc5b4\ud558\uae30 - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/41112\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"19.Nest.js\uc640 Next.js\uc5d0\uc11c Middleware\uc640 Guard \uc0ac\uc6a9\ud558\uae30, Nest.js\uc5d0\uc11c \ubbf8\ub4e4\uc6e8\uc5b4\uc640 \uac00\ub4dc\ub85c \uc778\uc99d \ubc0f \uad8c\ud55c \uc81c\uc5b4\ud558\uae30 - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Nest.js\uc640 Next.js\ub294 \ud604\ub300\uc758 \uc6f9 \uc560\ud50c\ub9ac\ucf00\uc774\uc158 \uac1c\ubc1c\uc5d0 \uc788\uc5b4 \uac15\ub825\ud55c \ud504\ub808\uc784\uc6cc\ud06c\uc785\ub2c8\ub2e4. \uc774 \ub450 \ud504\ub808\uc784\uc6cc\ud06c\ub294 \uc27d\uac8c \uc2a4\ucf00\uc77c\ub9c1 \uac00\ub2a5\ud55c \uc560\ud50c\ub9ac\ucf00\uc774\uc158 \uc544\ud0a4\ud14d\ucc98\ub97c \uc81c\uacf5\ud569\ub2c8\ub2e4. \ubcf8 \uac15\uc88c\uc5d0\uc11c\ub294 Nest.js\uc640 Next.js\uc5d0\uc11c \uac01\uac01 Middleware\uc640 Guard\ub97c \uc0ac\uc6a9\ud558\uc5ec \uc778\uc99d \ubc0f \uad8c\ud55c \uc81c\uc5b4\ub97c \uad6c\ud604\ud558\ub294 \ubc29\ubc95\uc5d0 \ub300\ud574 \uc790\uc138\ud788 \uc124\uba85\ud558\uaca0\uc2b5\ub2c8\ub2e4. 1. Middleware\ub780? Middleware\ub294 \ub450 \uac1c\uc758 \ud568\uc218 \uac04\uc5d0 \uc2e4\ud589\ub418\ub294 \ucf54\ub4dc\ub85c, \uc8fc\ub85c \uc694\uccad(Request)\uacfc \uc751\ub2f5(Response) \uac1d\uccb4\uc5d0 \ub300\ud55c \ucc98\ub9ac\ub97c \uc218\ud589\ud558\ub294 \ub370 \uc0ac\uc6a9\ub429\ub2c8\ub2e4. \uc608\ub97c \ub4e4\uc5b4, &hellip; \ub354 \ubcf4\uae30 &quot;19.Nest.js\uc640 Next.js\uc5d0\uc11c Middleware\uc640 Guard \uc0ac\uc6a9\ud558\uae30, Nest.js\uc5d0\uc11c \ubbf8\ub4e4\uc6e8\uc5b4\uc640 \uac00\ub4dc\ub85c \uc778\uc99d \ubc0f \uad8c\ud55c \uc81c\uc5b4\ud558\uae30&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/41112\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-06T02:46:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-26T06:37:33+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"1\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/41112\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/41112\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"19.Nest.js\uc640 Next.js\uc5d0\uc11c Middleware\uc640 Guard \uc0ac\uc6a9\ud558\uae30, Nest.js\uc5d0\uc11c \ubbf8\ub4e4\uc6e8\uc5b4\uc640 \uac00\ub4dc\ub85c \uc778\uc99d \ubc0f \uad8c\ud55c \uc81c\uc5b4\ud558\uae30\",\"datePublished\":\"2024-11-06T02:46:37+00:00\",\"dateModified\":\"2024-11-26T06:37:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/41112\/\"},\"wordCount\":90,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"nextjs\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/41112\/\",\"url\":\"https:\/\/atmokpo.com\/w\/41112\/\",\"name\":\"19.Nest.js\uc640 Next.js\uc5d0\uc11c Middleware\uc640 Guard \uc0ac\uc6a9\ud558\uae30, Nest.js\uc5d0\uc11c \ubbf8\ub4e4\uc6e8\uc5b4\uc640 \uac00\ub4dc\ub85c \uc778\uc99d \ubc0f \uad8c\ud55c \uc81c\uc5b4\ud558\uae30 - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-06T02:46:37+00:00\",\"dateModified\":\"2024-11-26T06:37:33+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/41112\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/41112\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/41112\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"19.Nest.js\uc640 Next.js\uc5d0\uc11c Middleware\uc640 Guard \uc0ac\uc6a9\ud558\uae30, Nest.js\uc5d0\uc11c \ubbf8\ub4e4\uc6e8\uc5b4\uc640 \uac00\ub4dc\ub85c \uc778\uc99d \ubc0f \uad8c\ud55c \uc81c\uc5b4\ud558\uae30\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"19.Nest.js\uc640 Next.js\uc5d0\uc11c Middleware\uc640 Guard \uc0ac\uc6a9\ud558\uae30, Nest.js\uc5d0\uc11c \ubbf8\ub4e4\uc6e8\uc5b4\uc640 \uac00\ub4dc\ub85c \uc778\uc99d \ubc0f \uad8c\ud55c \uc81c\uc5b4\ud558\uae30 - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/41112\/","og_locale":"ko_KR","og_type":"article","og_title":"19.Nest.js\uc640 Next.js\uc5d0\uc11c Middleware\uc640 Guard \uc0ac\uc6a9\ud558\uae30, Nest.js\uc5d0\uc11c \ubbf8\ub4e4\uc6e8\uc5b4\uc640 \uac00\ub4dc\ub85c \uc778\uc99d \ubc0f \uad8c\ud55c \uc81c\uc5b4\ud558\uae30 - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Nest.js\uc640 Next.js\ub294 \ud604\ub300\uc758 \uc6f9 \uc560\ud50c\ub9ac\ucf00\uc774\uc158 \uac1c\ubc1c\uc5d0 \uc788\uc5b4 \uac15\ub825\ud55c \ud504\ub808\uc784\uc6cc\ud06c\uc785\ub2c8\ub2e4. \uc774 \ub450 \ud504\ub808\uc784\uc6cc\ud06c\ub294 \uc27d\uac8c \uc2a4\ucf00\uc77c\ub9c1 \uac00\ub2a5\ud55c \uc560\ud50c\ub9ac\ucf00\uc774\uc158 \uc544\ud0a4\ud14d\ucc98\ub97c \uc81c\uacf5\ud569\ub2c8\ub2e4. \ubcf8 \uac15\uc88c\uc5d0\uc11c\ub294 Nest.js\uc640 Next.js\uc5d0\uc11c \uac01\uac01 Middleware\uc640 Guard\ub97c \uc0ac\uc6a9\ud558\uc5ec \uc778\uc99d \ubc0f \uad8c\ud55c \uc81c\uc5b4\ub97c \uad6c\ud604\ud558\ub294 \ubc29\ubc95\uc5d0 \ub300\ud574 \uc790\uc138\ud788 \uc124\uba85\ud558\uaca0\uc2b5\ub2c8\ub2e4. 1. Middleware\ub780? Middleware\ub294 \ub450 \uac1c\uc758 \ud568\uc218 \uac04\uc5d0 \uc2e4\ud589\ub418\ub294 \ucf54\ub4dc\ub85c, \uc8fc\ub85c \uc694\uccad(Request)\uacfc \uc751\ub2f5(Response) \uac1d\uccb4\uc5d0 \ub300\ud55c \ucc98\ub9ac\ub97c \uc218\ud589\ud558\ub294 \ub370 \uc0ac\uc6a9\ub429\ub2c8\ub2e4. \uc608\ub97c \ub4e4\uc5b4, &hellip; \ub354 \ubcf4\uae30 \"19.Nest.js\uc640 Next.js\uc5d0\uc11c Middleware\uc640 Guard \uc0ac\uc6a9\ud558\uae30, Nest.js\uc5d0\uc11c \ubbf8\ub4e4\uc6e8\uc5b4\uc640 \uac00\ub4dc\ub85c \uc778\uc99d \ubc0f \uad8c\ud55c \uc81c\uc5b4\ud558\uae30\"","og_url":"https:\/\/atmokpo.com\/w\/41112\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-06T02:46:37+00:00","article_modified_time":"2024-11-26T06:37:33+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"1\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/41112\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/41112\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"19.Nest.js\uc640 Next.js\uc5d0\uc11c Middleware\uc640 Guard \uc0ac\uc6a9\ud558\uae30, Nest.js\uc5d0\uc11c \ubbf8\ub4e4\uc6e8\uc5b4\uc640 \uac00\ub4dc\ub85c \uc778\uc99d \ubc0f \uad8c\ud55c \uc81c\uc5b4\ud558\uae30","datePublished":"2024-11-06T02:46:37+00:00","dateModified":"2024-11-26T06:37:33+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/41112\/"},"wordCount":90,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["nextjs"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/41112\/","url":"https:\/\/atmokpo.com\/w\/41112\/","name":"19.Nest.js\uc640 Next.js\uc5d0\uc11c Middleware\uc640 Guard \uc0ac\uc6a9\ud558\uae30, Nest.js\uc5d0\uc11c \ubbf8\ub4e4\uc6e8\uc5b4\uc640 \uac00\ub4dc\ub85c \uc778\uc99d \ubc0f \uad8c\ud55c \uc81c\uc5b4\ud558\uae30 - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-06T02:46:37+00:00","dateModified":"2024-11-26T06:37:33+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/41112\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/41112\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/41112\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"19.Nest.js\uc640 Next.js\uc5d0\uc11c Middleware\uc640 Guard \uc0ac\uc6a9\ud558\uae30, Nest.js\uc5d0\uc11c \ubbf8\ub4e4\uc6e8\uc5b4\uc640 \uac00\ub4dc\ub85c \uc778\uc99d \ubc0f \uad8c\ud55c \uc81c\uc5b4\ud558\uae30"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/41112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=41112"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/41112\/revisions"}],"predecessor-version":[{"id":41113,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/41112\/revisions\/41113"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=41112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=41112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=41112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}