{"id":33222,"date":"2026-11-30T19:12:13","date_gmt":"2026-11-30T19:12:13","guid":{"rendered":"https:\/\/umang.pk\/2026\/11\/30\/angular-%d8%a7%d9%88%d8%b1-nestjs-%da%a9%d8%a7-%d8%a7%d8%b3%d8%aa%d8%b9%d9%85%d8%a7%d9%84-%da%a9%d8%b1%d8%aa%db%92-%db%81%d9%88%d8%a6%db%92-%d9%be%d8%b1%d9%88%da%88%da%a9%d8%b4%d9%86-%da%a9%db%92\/"},"modified":"2026-11-30T19:12:13","modified_gmt":"2026-11-30T19:12:13","slug":"angular-%d8%a7%d9%88%d8%b1-nestjs-%da%a9%d8%a7-%d8%a7%d8%b3%d8%aa%d8%b9%d9%85%d8%a7%d9%84-%da%a9%d8%b1%d8%aa%db%92-%db%81%d9%88%d8%a6%db%92-%d9%be%d8%b1%d9%88%da%88%da%a9%d8%b4%d9%86-%da%a9%db%92","status":"publish","type":"post","link":"https:\/\/umang.pk\/ur\/2026\/11\/30\/angular-%d8%a7%d9%88%d8%b1-nestjs-%da%a9%d8%a7-%d8%a7%d8%b3%d8%aa%d8%b9%d9%85%d8%a7%d9%84-%da%a9%d8%b1%d8%aa%db%92-%db%81%d9%88%d8%a6%db%92-%d9%be%d8%b1%d9%88%da%88%da%a9%d8%b4%d9%86-%da%a9%db%92\/","title":{"rendered":"Angular \u0627\u0648\u0631 NestJS \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 \u067e\u0631\u0648\u0688\u06a9\u0634\u0646 \u06a9\u06d2 \u0644\u06cc\u06d2 \u062a\u06cc\u0627\u0631 \u062a\u0635\u062f\u06cc\u0642 \u0627\u0648\u0631 \u0627\u062c\u0627\u0632\u062a \u06a9\u0627 \u0646\u0638\u0627\u0645 \u06a9\u06cc\u0633\u06d2 \u0628\u0646\u0627\u06cc\u0627 \u062c\u0627\u0626\u06d2\u06d4"},"content":{"rendered":"\n<div id=\"\">\n<p>\u062a\u0648\u062b\u06cc\u0642 \u0627\u0646 \u0645\u0648\u0636\u0648\u0639\u0627\u062a \u0645\u06cc\u06ba \u0633\u06d2 \u0627\u06cc\u06a9 \u06c1\u06d2 \u062c\u0648 \u0622\u0633\u0627\u0646 \u0644\u06af\u062a\u0627 \u06c1\u06d2\u06d4 \u0635\u0627\u0631\u0641 \u0635\u0627\u0631\u0641 \u0646\u0627\u0645 \u0627\u0648\u0631 \u067e\u0627\u0633 \u0648\u0631\u0688 \u062c\u0645\u0639 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0633\u0631\u0648\u0631 \u0627\u0633\u0646\u0627\u062f \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0627\u06cc\u06a9 \u0679\u0648\u06a9\u0646 \u0648\u0627\u067e\u0633 \u06a9\u0631\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<p>\u062a\u0627\u06c1\u0645\u060c \u0627\u06cc\u06a9 \u0645\u062d\u0641\u0648\u0638 \u062a\u0635\u062f\u06cc\u0642\u06cc \u0646\u0638\u0627\u0645 \u0645\u06cc\u06ba JSON \u0648\u06cc\u0628 \u0679\u0648\u06a9\u0646 (JWT) \u0628\u0646\u0627\u0646\u06d2 \u0633\u06d2 \u0632\u06cc\u0627\u062f\u06c1 \u0634\u0627\u0645\u0644 \u06c1\u06d2\u06d4 \u0622\u067e \u06a9\u0648 \u067e\u0627\u0633 \u0648\u0631\u0688 \u0627\u0633\u0679\u0648\u0631\u06cc\u062c\u060c \u0631\u0633\u0627\u0626\u06cc \u0627\u0648\u0631 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646\u0632\u060c \u0679\u0648\u06a9\u0646 \u0631\u0648\u0679\u06cc\u0634\u0646\u060c \u0633\u06cc\u0634\u0646 \u0645\u06cc\u0646\u062c\u0645\u0646\u0679\u060c \u0644\u0627\u06af \u0622\u0624\u0679\u060c \u06a9\u0646\u06a9\u0631\u0646\u0679 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba\u060c \u0627\u062c\u0627\u0632\u062a\u060c CSRF \u062a\u062d\u0641\u0638\u060c \u0634\u0631\u062d \u06a9\u0648 \u0645\u062d\u062f\u0648\u062f \u06a9\u0631\u0646\u06d2\u060c \u0627\u0646 \u067e\u0679 \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642\u060c CORS\u060c \u0645\u062d\u0641\u0648\u0638 \u06a9\u0648\u06a9\u06cc\u0632\u060c \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u06a9\u06cc \u0645\u0633\u062a\u0642\u0644 \u0645\u0632\u0627\u062c\u06cc\u060c \u0633\u06cc\u06a9\u06cc\u0648\u0631\u0679\u06cc \u0645\u0627\u0646\u06cc\u0679\u0631\u0646\u06af \u0648\u063a\u06cc\u0631\u06c1 \u067e\u0631 \u0628\u06be\u06cc \u063a\u0648\u0631 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u0641\u06c1\u0631\u0633\u062a \u062c\u0627\u0631\u06cc \u06c1\u06d2\u06d4<\/p>\n<p>\u0627\u0633 \u06c1\u06cc\u0646\u0688 \u0628\u06a9 \u0645\u06cc\u06ba\u060c \u06c1\u0645 \u0627\u0646\u06af\u0648\u0644\u0631\u060c NestJS\u060c MongoDB\u060c \u0627\u0648\u0631 Redis \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0628\u0646\u0627\u0626\u06d2 \u06af\u0626\u06d2 \u0641\u0644 \u0627\u0633\u0679\u06cc\u06a9 \u0627\u06cc\u067e\u0644\u06cc \u06a9\u06cc\u0634\u0646\u0632 \u06a9\u06d2 \u0644\u06cc\u06d2 \u062a\u0648\u062b\u06cc\u0642 \u0627\u0648\u0631 \u0627\u062c\u0627\u0632\u062a \u06a9\u06d2 \u0641\u0646 \u062a\u0639\u0645\u06cc\u0631 \u06a9\u0648 \u062a\u0644\u0627\u0634 \u06a9\u0631\u06cc\u06ba \u06af\u06d2\u06d4 \u06cc\u06c1\u0627\u06ba \u06c1\u0645\u0627\u0631\u0627 \u0645\u0642\u0635\u062f \u06cc\u06c1 \u0633\u0645\u062c\u06be\u0646\u0627 \u06c1\u06d2 \u06a9\u06c1 \u06c1\u0631 \u0627\u06cc\u06a9 \u062c\u0632\u0648 \u06a9\u0633 \u0686\u06cc\u0632 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0630\u0645\u06c1 \u062f\u0627\u0631 \u06c1\u06d2\u060c \u0648\u06c1 \u0627\u06cc\u06a9 \u0633\u0627\u062a\u06be \u06a9\u06cc\u0633\u06d2 \u06a9\u0627\u0645 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u0648\u0631 \u062d\u0642\u06cc\u0642\u06cc \u0627\u06cc\u067e\u0644\u06cc\u06a9\u06cc\u0634\u0646 \u06a9\u0648 \u062a\u0639\u06cc\u0646\u0627\u062a \u06a9\u0631\u0646\u06d2 \u0633\u06d2 \u067e\u06c1\u0644\u06d2 \u0622\u067e \u06a9\u0648 \u06a9\u0646 \u0627\u0636\u0627\u0641\u06cc \u06a9\u0646\u0679\u0631\u0648\u0644\u0632 \u06a9\u0648 \u0686\u06cc\u06a9 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2\u06d4<\/p>\n<p>\u0627\u0633 \u0688\u06cc\u0632\u0627\u0626\u0646 \u0645\u06cc\u06ba \u0627\u0646\u06af\u0648\u0644\u0631 \u0645\u06cc\u0645\u0648\u0631\u06cc \u0645\u06cc\u06ba \u0631\u06a9\u06be\u06cc \u06af\u0626\u06cc \u0645\u062e\u062a\u0635\u0631 \u0631\u0633\u0627\u0626\u06cc JWT \u0627\u0648\u0631 HttpOnly \u06a9\u0648\u06a9\u06cc \u0633\u06d2 \u06af\u0632\u0631\u06d2 \u06c1\u0648\u0626\u06d2 \u0627\u06cc\u06a9 \u0645\u0628\u06c1\u0645 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2\u06d4 \u0628\u06cc\u06a9 \u0627\u06cc\u0646\u0688 \u0645\u0648\u0646\u06af\u0648 \u0688\u06cc \u0628\u06cc \u0645\u06cc\u06ba \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646\u0632 \u06a9\u06cc \u06c1\u06cc\u0634\u0632 \u06a9\u0648 \u0627\u0633\u0679\u0648\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0644\u0627\u06af \u0627\u0646 \u06a9\u0648 \u0679\u0631\u06cc\u06a9 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0633\u06cc\u0634\u0646 \u0631\u06cc\u06a9\u0627\u0631\u0688\u0632 \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u0634\u0631\u062d \u06a9\u0648 \u0645\u062d\u062f\u0648\u062f \u06a9\u0631\u0646\u06d2 \u0627\u0648\u0631 \u062f\u06cc\u06af\u0631 \u0639\u0627\u0631\u0636\u06cc \u062d\u0627\u0644\u062a \u06a9\u06d2 \u0644\u06cc\u06d2 Redis \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0633\u0631\u0648\u0631 (\u06a9\u0648\u0626\u06cc UI \u0646\u06c1\u06cc\u06ba) \u062a\u0635\u062f\u06cc\u0642 \u0627\u0648\u0631 \u0627\u062c\u0627\u0632\u062a \u06a9\u06d2 \u0644\u0626\u06d2 \u0627\u06cc\u06a9 \u0645\u062d\u0641\u0648\u0638 \u062f\u0627\u0626\u0631\u06c1 \u0628\u0631\u0642\u0631\u0627\u0631 \u0631\u06a9\u06be\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<h2 id=\"heading-table-of-contents\">\u0627\u0646\u0688\u06cc\u06a9\u0633<\/h2>\n<h2 id=\"heading-prerequisites\">\u0634\u0631\u0637\u06cc\u06ba<\/h2>\n<p>\u0627\u06af\u0631 \u0622\u067e JavaScript \u0627\u0648\u0631 TypeScript \u06a9\u06cc \u0628\u0646\u06cc\u0627\u062f\u06cc \u0628\u0627\u062a\u06cc\u06ba \u067e\u06c1\u0644\u06d2 \u0633\u06d2 \u062c\u0627\u0646\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u0648\u0631 \u0622\u067e \u0646\u06d2 \u0627\u0646\u06af\u0648\u0644\u0631 \u06cc\u0627 \u06a9\u0633\u06cc \u062f\u0648\u0633\u0631\u06d2 \u0641\u0631\u0646\u0679 \u0627\u06cc\u0646\u0688 \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 \u0627\u06cc\u06a9 \u0686\u06be\u0648\u0679\u06cc \u0627\u06cc\u067e\u0644\u06cc \u06a9\u06cc\u0634\u0646 \u0628\u0646\u0627\u0626\u06cc \u06c1\u06d2\u060c \u062a\u0648 \u06cc\u06c1 \u0679\u06cc\u0648\u0679\u0648\u0631\u06cc\u0644 \u0622\u0633\u0627\u0646\u06cc \u0633\u06d2 \u0642\u0627\u0628\u0644 \u0631\u0633\u0627\u0626\u06cc \u06c1\u0648 \u06af\u0627\u06d4 \u0627\u06af\u0631 \u0622\u067e HTTP \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba\u060c REST APIs\u060c \u0627\u0648\u0631 \u0628\u0646\u06cc\u0627\u062f\u06cc \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u0622\u067e\u0631\u06cc\u0634\u0646\u0632 \u0633\u06d2 \u0648\u0627\u0642\u0641 \u06c1\u06cc\u06ba \u062a\u0648 \u0645\u062b\u0627\u0644\u0648\u06ba \u06a9\u06cc \u067e\u06cc\u0631\u0648\u06cc \u06a9\u0631\u0646\u0627 \u0622\u0633\u0627\u0646 \u06c1\u0648\u06af\u0627\u06d4 \u0622\u067e \u06a9\u0648 \u0633\u06cc\u06a9\u06cc\u0648\u0631\u0679\u06cc \u0645\u0627\u06c1\u0631 \u0628\u0646\u0646\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u060c \u0644\u06cc\u06a9\u0646 \u0622\u067e \u06a9\u0648 \u0628\u06cc\u06a9 \u0627\u06cc\u0646\u0688 \u0679\u0627\u0626\u067e \u0627\u0633\u06a9\u0631\u067e\u0679 \u067e\u0691\u06be\u0646\u06d2 \u0645\u06cc\u06ba \u0627\u0686\u06be\u0627 \u06c1\u0648\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<p>\u0622\u067e \u06a9\u0648 Node.js \u0627\u0648\u0631 npm\u060c Angular CLI\u060c NestJS \u067e\u0631\u0648\u062c\u06cc\u06a9\u0679\u0633\u060c MongoDB\u060c Redis\u060c \u0627\u0648\u0631 Postman\u060c \u06cc\u0627 HTTP \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u0628\u06be\u06cc\u062c\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0679\u0648\u0644\u0632 \u06a9\u06cc \u0628\u06be\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u06af\u06cc\u06d4 <code>curl<\/code>. \u06af\u0679 \u0627\u0648\u0631 \u0648\u06cc \u0627\u06cc\u0633 \u06a9\u0648\u0688 \u062c\u06cc\u0633\u06d2 \u0627\u06cc\u0688\u06cc\u0679\u0631\u0632 \u0628\u06be\u06cc \u06a9\u0627\u0631\u0622\u0645\u062f \u06c1\u06cc\u06ba\u06d4 \u0622\u067e MongoDB \u0627\u0648\u0631 Redis \u06a9\u0648 \u0645\u0642\u0627\u0645\u06cc \u0637\u0648\u0631 \u067e\u0631 \u0686\u0644\u0627 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba \u06cc\u0627 \u0627\u06cc\u06a9 \u0645\u0646\u0638\u0645 \u062a\u0631\u0642\u06cc\u0627\u062a\u06cc \u0645\u062b\u0627\u0644 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u0630\u06cc\u0644 \u06a9\u0627 \u0679\u06a9\u0691\u0627 \u0688\u06cc\u0632\u0627\u0626\u0646 \u06a9\u06d2 \u0627\u06c1\u0645 \u062d\u0635\u0648\u06ba \u06a9\u0648 \u0638\u0627\u06c1\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u062a\u0627\u06c1\u0645\u060c \u06cc\u06c1 \u0622\u067e \u06a9\u06d2 \u067e\u0648\u0631\u06d2 \u0630\u062e\u06cc\u0631\u06c1 \u06a9\u0648 \u0686\u06cc\u06a9 \u06a9\u0631\u0646\u06d2\u060c \u062a\u0645\u0627\u0645 \u0627\u062e\u062a\u062a\u0627\u0645\u06cc \u0646\u0642\u0637\u0648\u06ba \u06a9\u0648 \u062a\u0631\u062a\u06cc\u0628 \u062f\u06cc\u0646\u06d2\u060c \u0627\u0648\u0631 \u062e\u0648\u062f\u06a9\u0627\u0631 \u0633\u06cc\u06a9\u06cc\u0648\u0631\u0679\u06cc \u0679\u06cc\u0633\u0679 \u0686\u0644\u0627\u0646\u06d2 \u06a9\u0627 \u06a9\u0648\u0626\u06cc \u0645\u062a\u0628\u0627\u062f\u0644 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u067e\u06cc\u06a9\u06cc\u062c \u0648\u0631\u0698\u0646 \u0627\u0648\u0631 \u0628\u0648\u0679\u0633\u0679\u0631\u06cc\u067e \u06a9\u06cc \u06a9\u0686\u06be \u062a\u0641\u0635\u06cc\u0644\u0627\u062a \u067e\u0631\u0648\u062c\u06cc\u06a9\u0679 \u0648\u0631\u0698\u0646 \u06a9\u06d2 \u062f\u0631\u0645\u06cc\u0627\u0646 \u0645\u062e\u062a\u0644\u0641 \u06c1\u0648 \u0633\u06a9\u062a\u06cc \u06c1\u06cc\u06ba\u06d4<\/p>\n<h2 id=\"heading-1-authentication-vs-authorization\">1. \u062a\u0635\u062f\u06cc\u0642 \u0627\u0648\u0631 \u0645\u0646\u0638\u0648\u0631\u06cc<\/h2>\n<p>\u0627\u0633 \u0633\u06d2 \u067e\u06c1\u0644\u06d2 \u06a9\u06c1 \u06c1\u0645 \u0634\u0631\u0648\u0639 \u06a9\u0631\u06cc\u06ba\u060c \u0622\u067e \u06a9\u0648 \u0627\u0646 \u062f\u0648 \u0627\u0635\u0637\u0644\u0627\u062d\u0627\u062a \u06a9\u06d2 \u062f\u0631\u0645\u06cc\u0627\u0646 \u0641\u0631\u0642 \u062c\u0627\u0646\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<p>\u0633\u0631\u0679\u06cc\u0641\u06cc\u06a9\u06cc\u0634\u0646 \u0633\u0648\u0627\u0644 \u06a9\u0627 \u062c\u0648\u0627\u0628 \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u060c &quot;\u0622\u067e \u06a9\u0648\u0646 \u06c1\u06cc\u06ba\u061f&#8221; \u0633\u0631\u0648\u0631 \u0627\u0633\u0646\u0627\u062f \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u06cc\u0627 \u0645\u0648\u062c\u0648\u062f\u06c1 \u0633\u06cc\u0634\u0646 \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0633\u06d2 \u0648\u0627\u0628\u0633\u062a\u06c1 \u0634\u0646\u0627\u062e\u062a \u06a9\u0627 \u062a\u0639\u06cc\u0646 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0645\u062b\u0627\u0644 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631\u060c \u0635\u0627\u0631\u0641 \u0627\u06cc\u06a9 \u0627\u06cc \u0645\u06cc\u0644 \u0627\u06cc\u0688\u0631\u06cc\u0633 \u0627\u0648\u0631 \u067e\u0627\u0633 \u0648\u0631\u0688 \u062c\u0645\u0639 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u06af\u0631 \u0627\u0633\u0646\u0627\u062f \u062f\u0631\u0633\u062a \u06c1\u06cc\u06ba\u060c \u062a\u0648 \u0633\u0631\u0648\u0631 \u0635\u0627\u0631\u0641 \u06a9\u06cc \u0634\u0646\u0627\u062e\u062a \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u06a9\u0644\u0627\u0626\u0646\u0679\u0633 \u06a9\u0648 \u0627\u0633 \u0634\u0646\u0627\u062e\u062a \u06a9\u0648 \u0645\u0646\u062a\u062e\u0628 \u06a9\u0631\u0646\u06d2 \u06cc\u0627 \u063a\u0644\u0637 \u062b\u0627\u0628\u062a \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u0646\u06c1\u06cc\u06ba \u06c1\u0648\u0646\u06cc \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<p>\u0627\u062c\u0627\u0632\u062a \u0627\u06cc\u06a9 \u0627\u0648\u0631 \u0633\u0648\u0627\u0644 \u06a9\u0627 \u062c\u0648\u0627\u0628 \u062f\u06cc\u062a\u06cc \u06c1\u06d2: &quot;\u06cc\u06c1 \u0645\u0633\u062a\u0646\u062f \u0635\u0627\u0631\u0641 \u06a9\u06cc\u0627 \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u061f&#8221; \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0635\u0627\u0631\u0641 <code>ADMIN<\/code> \u06a9\u0631\u062f\u0627\u0631\u0648\u06ba \u06a9\u0648 \u0627\u06a9\u0627\u0624\u0646\u0679\u0633 \u06a9\u0627 \u0627\u0646\u062a\u0638\u0627\u0645 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc \u062c\u0627 \u0633\u06a9\u062a\u06cc \u06c1\u06d2\u060c \u0644\u06cc\u06a9\u0646 \u0628\u0627\u0642\u0627\u0639\u062f\u06c1 \u06a9\u0631\u062f\u0627\u0631 <code>USER<\/code> \u0622\u067e \u06a9\u0648 \u0635\u0631\u0641 \u0627\u067e\u0646\u0627 \u067e\u0631\u0648\u0641\u0627\u0626\u0644 \u062f\u06cc\u06a9\u06be\u0646\u06d2 \u06cc\u0627 \u0627\u067e \u0688\u06cc\u0679 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc \u062c\u0627 \u0633\u06a9\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<p>\u0627\u0633 \u0633\u06d2 \u067e\u06c1\u0644\u06d2 \u06a9\u06c1 \u0645\u062d\u0641\u0648\u0638 \u0627\u062c\u0627\u0632\u062a \u06a9\u06d2 \u0642\u0648\u0627\u0646\u06cc\u0646 \u06a9\u0627 \u062c\u0627\u0626\u0632\u06c1 \u0644\u06cc\u0627 \u062c\u0627 \u0633\u06a9\u06d2 \u062a\u0648\u062b\u06cc\u0642 \u06c1\u0648\u0646\u06cc \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u062a\u0627\u06c1\u0645\u060c \u0635\u0631\u0641 \u06a9\u0631\u062f\u0627\u0631 \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642 \u06c1\u06cc \u06a9\u0627\u0641\u06cc \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 <code>\/orders\/123<\/code> \u0622\u067e \u06a9\u0648 \u06cc\u06c1 \u0628\u06be\u06cc \u06cc\u0642\u06cc\u0646\u06cc \u0628\u0646\u0627\u0646\u0627 \u06c1\u0648\u06af\u0627 \u06a9\u06c1 \u0645\u0648\u062c\u0648\u062f\u06c1 \u0635\u0627\u0631\u0641 \u06a9\u0648 \u0627\u0633 \u0645\u062e\u0635\u0648\u0635 \u0622\u0631\u0688\u0631 \u062a\u06a9 \u0631\u0633\u0627\u0626\u06cc \u062d\u0627\u0635\u0644 \u06c1\u06d2\u06d4 \u062c\u0628 \u06c1\u0645 \u0630\u06cc\u0644 \u0645\u06cc\u06ba RBAC \u0627\u0648\u0631 \u0648\u0633\u0627\u0626\u0644 \u06a9\u06cc \u0645\u0644\u06a9\u06cc\u062a \u067e\u0631 \u0628\u0627\u062a \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba \u062a\u0648 \u06c1\u0645 \u0627\u0633 \u0627\u0645\u062a\u06cc\u0627\u0632 \u067e\u0631 \u0648\u0627\u067e\u0633 \u0622\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<h2 id=\"heading-2-the-architecture\">2. \u0641\u0646 \u062a\u0639\u0645\u06cc\u0631<\/h2>\n<p>\u0628\u0631\u0627\u0624\u0632\u0631 \u0627\u0646\u06af\u0648\u0644\u0631 \u0627\u06cc\u067e\u0644\u06cc\u06a9\u06cc\u0634\u0646 \u0686\u0644\u0627\u062a\u0627 \u06c1\u06d2\u060c \u062c\u0628\u06a9\u06c1 NestJS API \u06a9\u0648 \u0628\u06d2 \u0646\u0642\u0627\u0628 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u062d\u0641\u0627\u0638\u062a\u06cc \u0641\u06cc\u0635\u0644\u06d2 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 MongoDB \u067e\u0627\u0626\u06cc\u062f\u0627\u0631 \u0635\u0627\u0631\u0641\u060c \u0633\u06cc\u0634\u0646\u060c \u0627\u0648\u0631 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0631\u06cc\u06a9\u0627\u0631\u0688\u0632 \u06a9\u0648 \u0627\u0633\u0679\u0648\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 Redis \u0634\u0631\u062d \u06a9\u0648 \u0645\u062d\u062f\u0648\u062f \u06a9\u0631\u0646\u06d2 \u0627\u0648\u0631 \u062f\u0648\u0633\u0631\u06cc \u0639\u0627\u0631\u0636\u06cc \u06cc\u0627 \u0645\u0634\u062a\u0631\u06a9\u06c1 \u062d\u0627\u0644\u062a \u06a9\u0648 \u0633\u067e\u0648\u0631\u0679 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u062c\u0648 \u06a9\u0633\u06cc \u0627\u06cc\u06a9 API \u0639\u0645\u0644 \u067e\u0631 \u0645\u0646\u062d\u0635\u0631 \u0646\u06c1\u06cc\u06ba \u06c1\u0648\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<pre><code class=\"language-text\">                    Angular\n                       \u2502\n             \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n             \u2502                   \u2502\n       Access Token        Refresh Cookie\n             \u2502                   \u2502\n             \u25bc                   \u25bc\n      Authorization Header    HttpOnly\n             \u2502                   \u2502\n             \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n                       \u25bc\n                    NestJS\n                       \u2502\n              \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n              \u2502                 \u2502\n      Authentication      Authorization\n              \u2502                 \u2502\n         JWT Strategy       RolesGuard\n              \u2502                 \u2502\n              \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n                       \u2502\n                       \u25bc\n                    Service\n                       \u2502\n              \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n              \u25bc                 \u25bc\n           MongoDB            Redis\n              \u2502                 \u2502\n       Users\/Sessions       Rate Limits\n       Refresh Tokens       Temporary State\n<\/code><\/pre>\n<p>\u06c1\u0645 \u0627\u06cc\u06a9 \u06c1\u0627\u0626\u0628\u0631\u0688 \u062a\u0635\u062f\u06cc\u0642\u06cc \u0645\u0627\u0688\u0644 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u06cc\u06ba \u06af\u06d2\u06d4 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u06a9\u0648 Angular \u0627\u0648\u0631 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06c1 \u0645\u06cc\u0645\u0648\u0631\u06cc \u0645\u06cc\u06ba \u0631\u06a9\u06be\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 <code>Authorization<\/code> \u06c1\u06cc\u0688\u0631 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0627\u06cc\u06a9 \u0627\u0646\u06a9\u0631\u067e\u0679\u0688 \u0631\u06cc\u0646\u0688\u0645 \u0627\u0648\u067e\u06cc\u06a9 \u0648\u06cc\u0644\u06cc\u0648 \u06c1\u06d2 (\u0627\u06cc\u06a9 \u0627\u0648\u0631 JWT \u0646\u06c1\u06cc\u06ba) \u0627\u0648\u0631 \u0628\u0631\u0627\u0624\u0632\u0631 \u06a9\u06cc \u0637\u0631\u0641 \u0633\u06d2 HttpOnly \u06a9\u0648\u06a9\u06cc \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0628\u06be\u06cc\u062c\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 MongoDB \u0635\u0631\u0641 \u0627\u0633 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u06c1\u06cc\u0634 \u06a9\u0648 \u0627\u067e\u0646\u06d2 \u0633\u06cc\u0634\u0646 \u0627\u0648\u0631 \u0644\u0627\u0626\u0641 \u0633\u0627\u0626\u06cc\u06a9\u0644 \u0645\u06cc\u0679\u0627 \u0688\u06cc\u0679\u0627 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0627\u0633\u0679\u0648\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u06cc\u06c1 \u0630\u0645\u06c1 \u062f\u0627\u0631\u06cc \u06a9\u06cc \u062c\u0627\u0646 \u0628\u0648\u062c\u06be \u06a9\u0631 \u062a\u0642\u0633\u06cc\u0645 \u06c1\u06d2\u06d4 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 API \u06a9\u0648 \u0628\u0627\u0642\u0627\u0639\u062f\u06c1 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u0648\u0631 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0633\u0631\u0648\u0631 \u06a9\u0648 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648\u0646\u06d2 \u06a9\u06d2 \u0628\u0639\u062f \u0628\u06be\u06cc \u0633\u06cc\u0634\u0646 \u062c\u0627\u0631\u06cc \u0631\u06a9\u06be\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646\u0632 \u06a9\u0648 \u0633\u0631\u0648\u0631 \u0633\u0627\u0626\u06cc\u0688 \u067e\u0631 \u0679\u0631\u06cc\u06a9 \u06a9\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u060c \u0644\u06c1\u0630\u0627 \u0627\u0646\u06c1\u06cc\u06ba \u06af\u06be\u0645\u0627\u06cc\u0627 \u0627\u0648\u0631 \u0645\u0646\u0633\u0648\u062e \u06a9\u06cc\u0627 \u062c\u0627 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 \u062a\u0627\u06c1\u0645\u060c \u062f\u0633\u062a\u062e\u0637 \u0634\u062f\u06c1 JWTs \u06a9\u0648 \u062e\u0648\u062f \u0628\u062e\u0648\u062f \u0645\u0646\u0633\u0648\u062e \u0646\u06c1\u06cc\u06ba \u06a9\u06cc\u0627 \u062c\u0627 \u0633\u06a9\u062a\u0627\u06d4 \u0627\u06af\u0631 \u0641\u0648\u0631\u06cc \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u0645\u0646\u0633\u0648\u062e\u06cc \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648 \u062a\u0648\u060c API \u06a9\u0648 \u0633\u06cc\u0634\u0646 \u06a9\u06cc \u062d\u0627\u0644\u062a \u06a9\u0648 \u0686\u06cc\u06a9 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2 \u06cc\u0627 \u0645\u062d\u0641\u0648\u0638 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u0646\u0633\u0648\u062e\u06cc \u06a9\u06cc \u062f\u0648\u0633\u0631\u06cc \u062d\u06a9\u0645\u062a \u0639\u0645\u0644\u06cc \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<h2 id=\"heading-3-what-we-will-build\">3. \u06c1\u0645 \u06a9\u06cc\u0627 \u062a\u0639\u0645\u06cc\u0631 \u06a9\u0631\u06cc\u06ba \u06af\u06d2<\/h2>\n<p>\u0627\u0633 \u0633\u06d2 \u067e\u06c1\u0644\u06d2 \u06a9\u06c1 \u06c1\u0645 \u0628\u0631\u0627\u0624\u0632\u0631 \u0627\u0633\u0679\u0648\u0631\u06cc\u062c \u067e\u0631 \u0628\u0627\u062a \u06a9\u0631\u06cc\u06ba\u060c \u0622\u0626\u06cc\u06d2 \u0627\u0633\u06a9\u0648\u067e \u0633\u06cc\u0679 \u06a9\u0631\u06cc\u06ba\u06d4 \u0645\u062b\u0627\u0644 \u06a9\u06d2 \u0641\u0646 \u062a\u0639\u0645\u06cc\u0631 \u0645\u06cc\u06ba \u0627\u06a9\u0627\u0624\u0646\u0679 \u0631\u062c\u0633\u0679\u0631\u06cc\u0634\u0646\u060c \u067e\u0627\u0633 \u0648\u0631\u0688 \u06c1\u06cc\u0634\u0646\u06af\u060c \u0644\u0627\u06af \u0627\u0646\u060c \u0642\u0644\u06cc\u0644 \u0627\u0644\u0645\u062f\u062a \u0631\u0633\u0627\u0626\u06cc JWTs\u060c \u0645\u0628\u06c1\u0645 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646\u060c \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0631\u0648\u0679\u06cc\u0634\u0646 \u0627\u0648\u0631 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0627 \u067e\u062a\u06c1 \u0644\u06af\u0627\u0646\u06d2\u060c \u0641\u06cc \u0688\u06cc\u0648\u0627\u0626\u0633 \u0633\u06cc\u0634\u0646\u0632\u060c \u0644\u0627\u06af \u0622\u0624\u0679\u060c \u0631\u0648\u0644 \u067e\u0631 \u0645\u0628\u0646\u06cc \u0631\u0633\u0627\u0626\u06cc \u06a9\u0646\u0679\u0631\u0648\u0644\u060c \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642\u060c CSRF \u06a9\u06d2 \u062a\u062d\u0641\u0638\u0627\u062a\u060c \u0627\u0648\u0631 CORS \u0627\u0648\u0631 Redis \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0631\u06cc\u0679 \u0645\u062d\u062f\u0648\u062f \u06a9\u0631\u0646\u0627 \u0634\u0627\u0645\u0644 \u06c1\u06d2\u06d4<\/p>\n<p>\u0627\u0646\u06af\u0648\u0644\u0631 \u0633\u0627\u0626\u06cc\u0688 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u0645\u06cc\u0645\u0648\u0631\u06cc \u0645\u06cc\u06ba \u0631\u06a9\u06be\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0633\u06d2 \u0645\u062d\u0641\u0648\u0638 API \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0645\u06cc\u06ba \u0634\u0627\u0645\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648\u0646\u06d2 \u0627\u0648\u0631 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648\u0646\u06d2 \u067e\u0631 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0648\u0634\u0634 \u06a9\u0648 \u0645\u0631\u0628\u0648\u0637 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 NestJS \u0633\u0627\u0626\u0688 \u0627\u0633\u0646\u0627\u062f \u0627\u0648\u0631 \u0679\u0648\u06a9\u0646\u0632 \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0627\u062c\u0627\u0632\u062a\u0648\u06ba \u06a9\u0627 \u0627\u0637\u0644\u0627\u0642 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u0633\u0631\u0648\u0631 \u0633\u0627\u0626\u06cc\u0688 \u0633\u06cc\u0634\u0646 \u06a9\u06cc \u062d\u0627\u0644\u062a \u06a9\u0648 \u0627\u067e \u0688\u06cc\u0679 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 MongoDB \u067e\u0627\u0626\u06cc\u062f\u0627\u0631 IDs \u0627\u0648\u0631 \u0633\u06cc\u0634\u0646 \u06a9\u06cc \u062a\u0627\u0631\u06cc\u062e \u06a9\u0648 \u0627\u0633\u0679\u0648\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u062c\u0628 \u06a9\u06c1 \u06cc\u06c1 Redis \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u0631\u06cc\u0679 \u06a9\u0648 \u0645\u062d\u062f\u0648\u062f \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u062d\u0627\u0644\u062a \u0627\u0648\u0631 \u062f\u06cc\u06af\u0631 \u0639\u0627\u0631\u0636\u06cc \u0627\u06cc\u0688\u062c\u0633\u0679\u0645\u0646\u0679 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06af\u0631 \u062a\u0631\u062a\u06cc\u0628 \u062f\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u0648\u06d4<\/p>\n<p>\u06cc\u06c1 \u0627\u06cc\u06a9 \u0633\u06cc\u06a9\u06be\u0646\u06d2 \u06a9\u0627 \u0641\u0646 \u062a\u0639\u0645\u06cc\u0631 \u06c1\u06d2 \u0627\u0648\u0631 \u0627\u0633 \u0628\u0627\u062a \u06a9\u06cc \u0636\u0645\u0627\u0646\u062a \u0646\u06c1\u06cc\u06ba \u062f\u06cc\u062a\u0627 \u06a9\u06c1 \u062a\u0645\u0627\u0645 \u062a\u0639\u06cc\u0646\u0627\u062a\u06cc\u0627\u06ba \u067e\u06cc\u062f\u0627\u0648\u0627\u0631 \u06a9\u06d2 \u0644\u06cc\u06d2 \u062a\u06cc\u0627\u0631 \u06c1\u0648\u06ba \u06af\u06cc\u06d4 \u0622\u067e \u06a9\u0648 \u0627\u06cc \u0645\u06cc\u0644 \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642\u060c \u067e\u0627\u0633 \u0648\u0631\u0688 \u0631\u06cc \u0633\u06cc\u0679\u060c \u0645\u0644\u0679\u06cc \u0641\u06cc\u06a9\u0679\u0631 \u062a\u0648\u062b\u06cc\u0642\u060c \u0645\u0636\u0628\u0648\u0637 \u0622\u0688\u0679 \u0644\u0627\u06af\u0646\u06af\u060c \u0646\u06af\u0631\u0627\u0646\u06cc\u060c \u062a\u0639\u06cc\u0646\u0627\u062a\u06cc \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u062e\u0635\u0648\u0635 \u06a9\u0648\u06a9\u06cc \u0633\u06cc\u0679\u0646\u06af\u0632\u060c \u06a9\u0631\u0627\u0633 \u0679\u06cc\u0628 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u06cc\u0648\u0646\u0646\u06af\u060c \u0627\u0648\u0631 \u0622\u067e \u06a9\u06cc \u0627\u0635\u0644 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06cc \u0636\u0631\u0648\u0631\u06cc\u0627\u062a \u06a9\u06d2 \u0645\u0637\u0627\u0628\u0642 \u062e\u0648\u062f\u06a9\u0627\u0631 \u0633\u06cc\u06a9\u06cc\u0648\u0631\u0679\u06cc \u0679\u06cc\u0633\u0679\u0648\u06ba \u06a9\u0627 \u0627\u06cc\u06a9 \u0645\u06a9\u0645\u0644 \u0645\u062c\u0645\u0648\u0639\u06c1 \u0646\u0627\u0641\u0630 \u06a9\u0631\u0646\u06d2 \u0627\u0648\u0631 \u0627\u0633 \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u06af\u06cc\u06d4<\/p>\n<h2 id=\"heading-4-why-not-store-everything-in-localstorage\">4. \u0644\u0648\u06a9\u0644 \u0633\u0679\u0648\u0631\u06cc\u062c \u0645\u06cc\u06ba \u06c1\u0631 \u0686\u06cc\u0632 \u06a9\u0648 \u0630\u062e\u06cc\u0631\u06c1 \u06a9\u06cc\u0648\u06ba \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u062a\u06d2\u061f<\/h2>\n<p>\u0627\u06cc\u06a9 \u0639\u0627\u0645 \u0646\u0641\u0627\u0630 \u062f\u0631\u062c \u0630\u06cc\u0644 \u062c\u06af\u06c1 \u067e\u0631 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u0627\u0633\u0679\u0648\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2: <code>localStorage<\/code> \u0627\u0633 \u06a9\u06cc \u0648\u062c\u06c1 \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u06cc\u06c1 \u0635\u0641\u062d\u06c1 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0644\u0648\u0688 \u06c1\u0648\u0646\u06d2 \u0633\u06d2 \u0628\u0686 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u0645\u0646\u0641\u06cc \u067e\u06c1\u0644\u0648 \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u0633\u0648\u0631\u0633 \u067e\u0631 \u0686\u0644\u0646\u06d2 \u0648\u0627\u0644\u0627 \u06a9\u0648\u0626\u06cc \u0628\u06be\u06cc \u062c\u0627\u0648\u0627 \u0627\u0633\u06a9\u0631\u067e\u0679 \u0627\u0633\u06d2 \u067e\u0691\u06be \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u06af\u0631 \u06a9\u0648\u0626\u06cc \u062d\u0645\u0644\u06c1 \u0622\u0648\u0631 \u06a9\u0631\u0627\u0633 \u0633\u0627\u0626\u0679 \u0627\u0633\u06a9\u0631\u067e\u0679\u0646\u06af (XSS) \u06a9\u06cc \u06a9\u0645\u0632\u0648\u0631\u06cc \u06a9\u0627 \u0627\u0633\u062a\u062d\u0635\u0627\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u062a\u0648 \u0627\u0646\u062c\u06a9\u0634\u0646 \u0634\u062f\u06c1 JavaScript \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u067e\u0691\u06be \u0633\u06a9\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0627\u0633\u06d2 \u0628\u06cc\u0631\u0648\u0646\u06cc \u0633\u0631\u0648\u0631 \u06a9\u0648 \u0628\u06be\u06cc\u062c \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 \u06cc\u06c1\u0627\u06ba \u062a\u06a9 \u06a9\u06c1 \u0627\u06af\u0631 \u0679\u0648\u06a9\u0646 \u0635\u0631\u0641 \u0645\u06cc\u0645\u0648\u0631\u06cc \u0645\u06cc\u06ba \u0628\u0631\u0642\u0631\u0627\u0631 \u0631\u06c1\u062a\u0627 \u06c1\u06d2\u060c \u0648\u06c1\u06cc XSS \u0627\u06a9\u062b\u0631 \u0635\u0627\u0631\u0641 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0627\u06cc\u06a9 \u06c1\u06cc \u06a9\u0627\u0645 \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u060c \u0644\u06c1\u0630\u0627 \u0627\u0646 \u0645\u06cc\u0645\u0648\u0631\u06cc \u0627\u0633\u0679\u0648\u0631\u06cc\u062c \u0645\u0633\u062a\u0642\u0644 \u0627\u0648\u0631 \u0633\u0627\u062f\u06c1 \u0646\u06a9\u0627\u0644\u0646\u06d2 \u06a9\u0648 \u06a9\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0644\u06cc\u06a9\u0646 XSS \u06a9\u06d2 \u062e\u0637\u0631\u06d2 \u06a9\u0648 \u062e\u062a\u0645 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0627\u0633 \u0688\u06cc\u0632\u0627\u0626\u0646 \u0645\u06cc\u06ba\u060c \u0627\u0646\u06af\u0648\u0644\u0631 \u0645\u06cc\u0645\u0648\u0631\u06cc \u0645\u06cc\u06ba \u0627\u06cc\u06a9 \u0645\u062e\u062a\u0635\u0631 \u0645\u062f\u062a \u062a\u06a9 \u0631\u0633\u0627\u0626\u06cc \u06a9\u0627 \u0679\u0648\u06a9\u0646 \u0631\u06a9\u06be\u062a\u0627 \u06c1\u06d2\u06d4 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u06a9\u0648 HttpOnly \u06a9\u0648\u06a9\u06cc \u0645\u06cc\u06ba \u0645\u062d\u0641\u0648\u0638 \u06a9\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u060c \u062c\u0648 \u06a9\u06c1 \u0631\u06cc\u06af\u0648\u0644\u0631 \u067e\u06cc\u062c \u062c\u0627\u0648\u0627 \u0627\u0633\u06a9\u0631\u067e\u0679 \u06a9\u0648 \u0627\u0633 \u06a9\u06cc \u0642\u062f\u0631 \u067e\u0691\u06be\u0646\u06d2 \u0633\u06d2 \u0631\u0648\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 \u06cc\u06c1 \u0628\u0631\u0627\u06c1 \u0631\u0627\u0633\u062a \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0646\u06a9\u0627\u0644\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4 <code>document.cookie<\/code> \u06cc\u06c1 \u0632\u06cc\u0627\u062f\u06c1 \u0645\u0634\u06a9\u0644 \u06c1\u06d2\u060c \u0644\u06cc\u06a9\u0646 \u06cc\u06c1 XSS \u06a9\u0648 \u0628\u06d2 \u0636\u0631\u0631 \u0646\u06c1\u06cc\u06ba \u0628\u0646\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u06cc\u06c1 \u062e\u0648\u062f \u0633\u06d2 \u06a9\u0631\u0627\u0633 \u0633\u0627\u0626\u0679 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u062c\u0639\u0644 \u0633\u0627\u0632\u06cc (CSRF) \u06a9\u0648 \u0628\u06be\u06cc \u0646\u06c1\u06cc\u06ba \u0631\u0648\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 \u06a9\u0648\u06a9\u06cc \u067e\u0631 \u0645\u0628\u0646\u06cc \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0627\u06cc\u0646\u0688 \u067e\u0648\u0627\u0626\u0646\u0679\u0633 \u06a9\u0648 \u0627\u0628 \u0628\u06be\u06cc \u062c\u0627\u0646 \u0628\u0648\u062c\u06be \u06a9\u0631 SameSite \u067e\u0627\u0644\u06cc\u0633\u06cc \u0627\u0648\u0631 \u0645\u0646\u0627\u0633\u0628 CSRF\/\u0627\u0635\u0644 \u062f\u0641\u0627\u0639 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-text\">Angular Memory\n    \u2193\nAccess Token\n\nHttpOnly Cookie\n    \u2193\nRefresh Token\n<\/code><\/pre>\n<p>JavaScript HttpOnly \u06a9\u0648\u06a9\u06cc\u0632 \u06a9\u0648 \u0628\u0631\u0627\u06c1 \u0631\u0627\u0633\u062a \u0646\u06c1\u06cc\u06ba \u067e\u0691\u06be \u0633\u06a9\u062a\u0627\u060c \u0644\u06cc\u06a9\u0646 \u0628\u0631\u0627\u0624\u0632\u0631 \u067e\u06be\u0631 \u0628\u06be\u06cc \u0627\u0646\u06c1\u06cc\u06ba \u0645\u0645\u0627\u062b\u0644 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u0633\u06d2 \u0645\u0646\u0633\u0644\u06a9 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u06cc\u06c1\u06cc \u0648\u062c\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u06a9\u0648\u06a9\u06cc \u06a9\u0646\u0641\u06cc\u06af\u0631\u06cc\u0634\u0646 \u0627\u0648\u0631 CSRF \u0688\u06cc\u0641\u0646\u0633\u0632 \u0627\u06c1\u0645 \u06c1\u06cc\u06ba\u06d4<\/p>\n<h2 id=\"heading-5-project-structure\">5. \u067e\u0631\u0648\u062c\u06cc\u06a9\u0679 \u06a9\u0627 \u0688\u06be\u0627\u0646\u0686\u06c1<\/h2>\n<p>\u06cc\u06c1 \u0627\u06cc\u06a9 \u06c1\u06cc \u0641\u0644 \u0627\u0633\u0679\u06cc\u06a9 \u0627\u06cc\u067e\u0644\u06cc \u06a9\u06cc\u0634\u0646 \u06a9\u06d2 \u062f\u0648 \u062d\u0635\u06d2 \u06c1\u06cc\u06ba \u062c\u0648 \u0628\u0627\u06c1\u0645\u06cc \u0637\u0648\u0631 \u067e\u0631 \u062e\u0635\u0648\u0635\u06cc \u0645\u062a\u0628\u0627\u062f\u0644 \u0646\u06c1\u06cc\u06ba \u06c1\u06cc\u06ba\u06d4 NestJS \u0679\u0631\u06cc \u06a9\u0627 \u062a\u0639\u0644\u0642 \u0628\u06cc\u06a9 \u0627\u06cc\u0646\u0688 API \u0633\u06d2 \u06c1\u06d2 \u0627\u0648\u0631 \u0627\u0646\u06af\u0648\u0644\u0631 \u0679\u0631\u06cc \u06a9\u0627 \u062a\u0639\u0644\u0642 \u0628\u0631\u0627\u0624\u0632\u0631 \u06a9\u0644\u0627\u0626\u0646\u0679 \u0633\u06d2 \u06c1\u06d2\u06d4 \u0648\u06c1 \u0627\u0644\u06af \u0627\u0644\u06af \u0630\u062e\u06cc\u0631\u0648\u06ba \u06cc\u0627 \u0627\u0644\u06af \u0630\u062e\u06cc\u0631\u0648\u06ba \u0645\u06cc\u06ba \u06c1\u0648\u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 <code>apps\/api<\/code> \u0627\u0648\u0631 <code>apps\/web<\/code> Monorepo \u0641\u0648\u0644\u0688\u0631\u06d4<\/p>\n<p>\u0627\u06cc\u06a9 \u0627\u06cc\u0633\u0627 \u0627\u0646\u062a\u0638\u0627\u0645 \u0645\u0646\u062a\u062e\u0628 \u06a9\u0631\u06cc\u06ba \u062c\u0648 \u0622\u067e \u06a9\u06cc \u0679\u06cc\u0645 \u06a9\u06cc \u062a\u0639\u06cc\u0646\u0627\u062a\u06cc \u0627\u0648\u0631 \u0679\u0648\u0644\u0632 \u06a9\u06d2 \u0645\u0637\u0627\u0628\u0642 \u06c1\u0648\u06d4 \u062f\u0648\u0646\u0648\u06ba \u06a9\u0648 \u0627\u06a9\u0679\u06be\u0627 \u0646\u06c1 \u06a9\u0631\u06cc\u06ba\u06d4 <code>src<\/code> \u0627\u06cc\u06a9 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0688\u0627\u0626\u0631\u06a9\u0679\u0631\u06cc \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0627\u06cc\u06a9 \u062f\u0631\u062e\u062a \u0628\u0646\u0627\u0626\u06cc\u06ba\u06d4<\/p>\n<p>\u067e\u0633\u062f\u06cc\u062f \u062a\u0648\u062b\u06cc\u0642 \u06a9\u06d2 \u0627\u062e\u062a\u062a\u0627\u0645\u06cc \u0646\u0642\u0637\u0648\u06ba \u0627\u0648\u0631 \u0679\u0648\u06a9\u0646 \u0645\u0646\u0637\u0642 \u06a9\u0648 \u0635\u0627\u0631\u0641 \u06a9\u06d2 \u0688\u06cc\u0679\u0627\u060c \u0633\u06cc\u0634\u0646 \u0627\u0633\u062a\u0642\u0627\u0645\u062a\u060c \u0627\u0648\u0631 Redis \u0627\u0646\u0636\u0645\u0627\u0645 \u0633\u06d2 \u0627\u0644\u06af \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u06af\u0627\u0631\u0688\u0632 \u0627\u0648\u0631 \u0688\u06cc\u06a9\u0648\u0631\u06cc\u0679\u0631 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0642\u0627\u0628\u0644 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06cc \u0633\u0637\u062d \u06a9\u06d2 \u062d\u0641\u0627\u0638\u062a\u06cc \u0627\u0635\u0648\u0644 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0628\u0691\u06d2 \u0633\u0633\u0679\u0645\u0632 \u0645\u06cc\u06ba\u060c \u0627\u0646 \u0645\u06cc\u06ba \u0633\u06d2 \u06a9\u0686\u06be \u0630\u0645\u06c1 \u062f\u0627\u0631\u06cc\u0648\u06ba \u06a9\u0648 \u0627\u0636\u0627\u0641\u06cc \u0645\u0627\u0688\u06cc\u0648\u0644\u0632 \u0645\u06cc\u06ba \u062a\u0642\u0633\u06cc\u0645 \u06a9\u06cc\u0627 \u062c\u0627 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>NestJS \u06a9\u0627 \u0645\u0645\u06a9\u0646\u06c1 \u0688\u06be\u0627\u0646\u0686\u06c1 \u06cc\u06c1 \u06c1\u0648\u06af\u0627:<\/p>\n<pre><code class=\"language-text\">src\/\n\u251c\u2500\u2500 auth\/\n\u2502   \u251c\u2500\u2500 auth.controller.ts\n\u2502   \u251c\u2500\u2500 auth.service.ts\n\u2502   \u251c\u2500\u2500 auth.module.ts\n\u2502   \u251c\u2500\u2500 token.service.ts\n\u2502   \u251c\u2500\u2500 strategies\/\n\u2502   \u2502   \u2514\u2500\u2500 jwt.strategy.ts\n\u2502   \u251c\u2500\u2500 guards\/\n\u2502   \u2502   \u251c\u2500\u2500 jwt-auth.guard.ts\n\u2502   \u2502   \u251c\u2500\u2500 roles.guard.ts\n\u2502   \u2502   \u2514\u2500\u2500 csrf.guard.ts\n\u2502   \u2514\u2500\u2500 decorators\/\n\u2502       \u251c\u2500\u2500 public.decorator.ts\n\u2502       \u251c\u2500\u2500 roles.decorator.ts\n\u2502       \u2514\u2500\u2500 current-user.decorator.ts\n\u2502\n\u251c\u2500\u2500 users\/\n\u2502   \u251c\u2500\u2500 users.service.ts\n\u2502   \u251c\u2500\u2500 users.module.ts\n\u2502   \u2514\u2500\u2500 schemas\/\n\u2502       \u2514\u2500\u2500 user.schema.ts\n\u2502\n\u251c\u2500\u2500 sessions\/\n\u2502   \u251c\u2500\u2500 sessions.service.ts\n\u2502   \u251c\u2500\u2500 sessions.module.ts\n\u2502   \u2514\u2500\u2500 schemas\/\n\u2502       \u251c\u2500\u2500 session.schema.ts\n\u2502       \u2514\u2500\u2500 refresh-token.schema.ts\n\u2502\n\u251c\u2500\u2500 redis\/\n\u2502   \u251c\u2500\u2500 redis.service.ts\n\u2502   \u2514\u2500\u2500 redis.module.ts\n\u2502\n\u2514\u2500\u2500 app.module.ts\n<\/code><\/pre>\n<p>\u06a9\u0648\u0646\u06cc\u06cc \u0641\u0646 \u062a\u0639\u0645\u06cc\u0631 \u0627\u06cc\u06a9 \u06a9\u0644\u0627\u0626\u0646\u0679 \u0633\u0627\u0626\u06cc\u0688 \u0641\u0646 \u062a\u0639\u0645\u06cc\u0631 \u06c1\u06d2\u06d4 <code>AuthService<\/code> \u062a\u0635\u062f\u06cc\u0642 \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u0627\u0648\u0631 \u0627\u0646 \u0645\u06cc\u0645\u0648\u0631\u06cc \u062a\u06a9 \u0631\u0633\u0627\u0626\u06cc \u06a9\u06d2 \u0679\u0648\u06a9\u0646\u0632 \u06a9\u0627 \u0627\u0646\u062a\u0638\u0627\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0646\u0679\u0631\u0633\u06cc\u067e\u0679\u0631 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u0645\u0646\u0633\u0644\u06a9 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u062c\u06c1\u0627\u06ba \u0645\u0646\u0627\u0633\u0628 \u06c1\u0648 CSRF \u0633\u06d2 \u0645\u062a\u0639\u0644\u0642\u06c1 \u06c1\u06cc\u0688\u0631\u0632 \u067e\u0631 \u06a9\u0627\u0631\u0631\u0648\u0627\u0626\u06cc \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u06af\u0627\u0631\u0688\u0632 \u0628\u0631\u0627\u0624\u0632\u0646\u06af \u06a9\u06d2 \u062a\u062c\u0631\u0628\u06d2 \u06a9\u0648 \u0628\u06c1\u062a\u0631 \u0628\u0646\u0627\u062a\u06d2 \u06c1\u06cc\u06ba \u0644\u06cc\u06a9\u0646 \u0628\u06cc\u06a9 \u0627\u06cc\u0646\u0688 \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u06a9\u0648 \u062a\u0628\u062f\u06cc\u0644 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 <code>auth.types.ts<\/code> \u06a9\u0644\u0627\u0626\u0646\u0679 \u06a9\u06cc \u0637\u0631\u0641 \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a\/\u062c\u0648\u0627\u0628 \u06a9\u06cc \u0627\u0642\u0633\u0627\u0645 \u067e\u0631 \u0645\u0634\u062a\u0645\u0644 \u06c1\u06d2\u060c <code>auth.store.ts<\/code> \u062a\u0648\u062b\u06cc\u0642 \u06a9\u06cc \u062d\u0627\u0644\u062a \u06a9\u0648 \u0627\u062c\u0632\u0627\u0621 \u06a9\u06d2 \u0633\u0627\u0645\u0646\u06d2 \u0644\u0627\u06cc\u0627 \u062c\u0627 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u06a9\u0648\u0646\u06cc\u06cc \u062d\u0627\u0644\u062a \u0645\u06cc\u06ba \u0630\u062e\u06cc\u0631\u06c1 \u0646\u06c1 \u06a9\u0631\u06cc\u06ba\u06d4 \u0628\u0631\u0627\u0624\u0632\u0631 HttpOnly \u06a9\u0648\u06a9\u06cc\u0632 \u06a9\u0627 \u0646\u0638\u0645 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u06a9\u0648\u0646\u06cc\u06cc:<\/p>\n<pre><code class=\"language-text\">src\/app\/core\/auth\/\n\u251c\u2500\u2500 auth.service.ts\n\u251c\u2500\u2500 auth.interceptor.ts\n\u251c\u2500\u2500 csrf.interceptor.ts\n\u251c\u2500\u2500 auth.guard.ts\n\u251c\u2500\u2500 auth.types.ts\n\u2514\u2500\u2500 auth.store.ts\n<\/code><\/pre>\n<h2 id=\"heading-6-install-dependencies\">6. \u0627\u0646\u062d\u0635\u0627\u0631 \u0627\u0646\u0633\u0679\u0627\u0644 \u06a9\u0631\u06cc\u06ba\u06d4<\/h2>\n<p>\u0622\u067e \u06a9\u06d2 NestJS \u0628\u06cc\u06a9 \u0627\u06cc\u0646\u0688 \u067e\u0631\u0648\u062c\u06cc\u06a9\u0679 \u0645\u06cc\u06ba\u060c \u0686\u0644\u0627\u0626\u06cc\u06ba: \u06cc\u06c1 \u067e\u06cc\u06a9\u062c\u0632 \u06a9\u0646\u0641\u06cc\u06af\u0631\u06cc\u0634\u0646\u060c MongoDB \u0627\u0646\u0679\u06cc\u06af\u0631\u06cc\u0634\u0646\u060c JWT \u0627\u0648\u0631 \u067e\u0627\u0633\u067e\u0648\u0631\u0679 \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642\u060c \u067e\u0627\u0633 \u0648\u0631\u0688 \u06c1\u06cc\u0634\u0646\u06af\u060c \u06a9\u0648\u06a9\u06cc \u067e\u0627\u0631\u0633\u0646\u06af\u060c DTO \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642\u060c \u0627\u0648\u0631 Redis \u0631\u0633\u0627\u0626\u06cc \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0686\u06cc\u06a9 \u06a9\u0631\u06cc\u06ba \u06a9\u06c1 \u0622\u06cc\u0627 \u0622\u067e \u06a9\u06d2 \u0630\u062e\u06cc\u0631\u06d2 \u0645\u06cc\u06ba \u067e\u06c1\u0644\u06d2 \u0633\u06d2 \u06a9\u0686\u06be \u067e\u06cc\u06a9\u062c\u0632 \u06c1\u06cc\u06ba\u06d4 <code>package.json<\/code> \u06a9\u0644\u0648\u0646 \u0627\u0646\u0633\u0679\u0627\u0644 \u06a9\u0631\u0646\u06d2 \u0633\u06d2 \u067e\u06c1\u0644\u06d2\u06d4<\/p>\n<p>NestJS \u06a9\u06d2 \u0644\u06cc\u06d2:<\/p>\n<pre><code class=\"language-bash\">npm install \\\n  @nestjs\/config \\\n  @nestjs\/mongoose \\\n  @nestjs\/jwt \\\n  @nestjs\/passport \\\n  passport \\\n  passport-jwt \\\n  mongoose \\\n  bcrypt \\\n  cookie-parser \\\n  class-validator \\\n  class-transformer \\\n  ioredis\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u06c1\u06d2 \u0631\u0646 \u0679\u0627\u0626\u0645 \u0627\u0646\u062d\u0635\u0627\u0631 \u06a9\u06cc\u0627 \u06a9\u0631\u062a\u0627 \u06c1\u06d2:<\/p>\n<ul>\n<li><code>@nestjs\/config<\/code>    \u0645\u0627\u062d\u0648\u0644 \u06a9\u06cc \u062a\u0631\u062a\u06cc\u0628 \u06a9\u0648 \u0644\u0648\u0688 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0627\u0633 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u0627\u0633\u06d2 \u0628\u06d2 \u0646\u0642\u0627\u0628 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 <code>ConfigService<\/code>.<\/li>\n<li><code>@nestjs\/mongoose<\/code>    NestJS \u06a9\u06d2 \u0633\u0627\u062a\u06be Mongoose \u0645\u0627\u0688\u0644\u0632 \u06a9\u0648 \u0645\u0631\u0628\u0648\u0637 \u06a9\u0631\u06cc\u06ba\u06d4 <code>mongoose<\/code> \u0627\u0633\u06a9\u06cc\u0645\u0627 \u06a9\u06cc \u0648\u0636\u0627\u062d\u062a \u06a9\u0631\u06cc\u06ba \u0627\u0648\u0631 MongoDB \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0628\u0627\u062a \u0686\u06cc\u062a \u06a9\u0631\u06cc\u06ba\u06d4<\/li>\n<li><code>@nestjs\/jwt<\/code>    JWT \u067e\u0631 \u062f\u0633\u062a\u062e\u0637 \u06a9\u0631\u06cc\u06ba \u0627\u0648\u0631 \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0631\u06cc\u06ba\u06d4<\/li>\n<li><code>@nestjs\/passport<\/code>, <code>passport<\/code>\u0627\u0648\u0631 <code>passport-jwt<\/code> \u067e\u0627\u0633\u067e\u0648\u0631\u0679 \u06a9\u06cc \u062d\u06a9\u0645\u062a \u0639\u0645\u0644\u06cc \u06a9\u0648 NestJS \u062a\u0635\u062f\u06cc\u0642 \u06a9\u06d2 \u0628\u06c1\u0627\u0624 \u0633\u06d2 \u0645\u0631\u0628\u0648\u0637 \u06a9\u0631\u06cc\u06ba\u06d4<\/li>\n<li><code>bcrypt<\/code>    \u067e\u0627\u0633 \u0648\u0631\u0688 \u06a9\u0648 \u06c1\u06cc\u0634 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0644\u0627\u06af \u0627\u0646 \u06a9\u06cc \u06a9\u0648\u0634\u0634\u0648\u06ba \u06a9\u0648 \u0630\u062e\u06cc\u0631\u06c1 \u0634\u062f\u06c1 \u067e\u0627\u0633 \u0648\u0631\u0688 \u06c1\u06cc\u0634 \u0633\u06d2 \u0645\u0648\u0627\u0632\u0646\u06c1 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/li>\n<li><code>cookie-parser<\/code>    \u062c\u0648 \u0622\u062a\u0627 \u06c1\u06d2 \u0627\u0633\u06d2 \u067e\u0627\u0631\u0633 \u06a9\u0631\u06cc\u06ba\u06d4 <code>Cookie<\/code> \u0627\u06cc\u06a9\u0633\u067e\u0631\u06cc\u0633 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u0648 \u067e\u0627\u0631\u0633 \u0634\u062f\u06c1 \u06a9\u0648\u06a9\u06cc\u0632 \u06a9\u0648 \u0638\u0627\u06c1\u0631 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06c1\u06cc\u0688\u0631 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u06cc\u06ba\u06d4 \u0627\u06af\u0631 \u0622\u067e \u06a9\u06d2 \u0633\u06cc\u0679 \u0627\u067e \u06a9\u06d2 \u0644\u06cc\u06d2 \u0636\u0631\u0648\u0631\u062a \u06c1\u0648 \u062a\u0648 \u0645\u0688\u0644 \u0648\u06cc\u0626\u0631 \u06a9\u0648 \u0627\u067e\u0646\u06d2 \u0627\u06cc\u067e\u0644\u06cc\u06a9\u06cc\u0634\u0646 \u0628\u0648\u0679\u0633\u0679\u0631\u06cc\u067e \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0631\u062c\u0633\u0679\u0631 \u06a9\u0631\u06cc\u06ba\u06d4<\/li>\n<li><code>class-validator<\/code>    \u0627\u0648\u0631 <code>class-transformer<\/code> NestJS \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06c1\u0648\u0646\u06d2 \u067e\u0631 DTO \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u0627\u0648\u0631 \u062a\u0628\u062f\u06cc\u0644\u06cc \u06a9\u0648 \u0633\u067e\u0648\u0631\u0679 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 <code>ValidationPipe<\/code>.<\/li>\n<li><code>ioredis<\/code>    Redis \u06a9\u0644\u0627\u0626\u0646\u0679 \u06a9\u0648 \u0631\u06cc\u0679 \u0645\u062d\u062f\u0648\u062f \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u06a9\u0627\u0624\u0646\u0679\u0631\u0632 \u0627\u0648\u0631 \u062f\u06cc\u06af\u0631 \u0645\u0634\u062a\u0631\u06a9\u06c1 \u0639\u0627\u0631\u0636\u06cc \u062d\u0627\u0644\u062a \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4<\/li>\n<\/ul>\n<p>\u06a9\u06c1 <code>-D<\/code> \u067e\u0631\u0686\u0645 \u062a\u0631\u0642\u06cc \u06a9\u06d2 \u0627\u0646\u062d\u0635\u0627\u0631 \u06a9\u0648 \u0627\u0646\u0633\u0679\u0627\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u06a9\u06c1 <code>@types\/*<\/code> \u06cc\u06c1 \u067e\u06cc\u06a9\u06cc\u062c \u0644\u0627\u0626\u0628\u0631\u06cc\u0631\u06cc\u0648\u06ba \u06a9\u06d2 \u0644\u06cc\u06d2 TypeScript \u06a9\u06d2 \u0627\u0639\u0644\u0627\u0646\u0627\u062a \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u062c\u0648 \u062a\u0645\u0627\u0645 \u0645\u0637\u0644\u0648\u0628\u06c1 \u0627\u0642\u0633\u0627\u0645 \u0641\u0631\u0627\u06c1\u0645 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u06cc\u06c1 \u06a9\u0645\u067e\u0627\u0626\u0644\u0631\u0632 \u0627\u0648\u0631 \u0627\u06cc\u0688\u06cc\u0679\u0631\u0632 \u06a9\u0648 \u0633\u067e\u0648\u0631\u0679 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u06cc\u06c1 \u0627\u06cc\u067e\u0644\u06cc\u06a9\u06cc\u0634\u0646 \u0631\u0646 \u0679\u0627\u0626\u0645 \u0633\u0631\u0648\u0633 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u0635\u062d\u06cc\u062d \u0642\u0633\u0645 \u06a9\u0627 \u067e\u06cc\u06a9\u06cc\u062c \u0622\u067e \u06a9\u06d2 \u067e\u0631\u0648\u062c\u06cc\u06a9\u0679 \u0645\u06cc\u06ba \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06c1\u0648\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u0648\u0631\u0698\u0646 \u0627\u0648\u0631 \u0679\u0627\u0626\u067e \u0627\u0633\u06a9\u0631\u067e\u0679 \u06a9\u06cc \u062a\u0631\u062a\u06cc\u0628\u0627\u062a \u067e\u0631 \u0645\u0646\u062d\u0635\u0631 \u06c1\u06d2\u06d4<\/p>\n<p>\u062a\u0631\u0642\u06cc \u06a9\u06cc \u0642\u0633\u0645:<\/p>\n<pre><code class=\"language-bash\">npm install -D \\\n  @types\/bcrypt \\\n  @types\/cookie-parser \\\n  @types\/passport-jwt\n<\/code><\/pre>\n<h2 id=\"heading-7-environment-configuration\">7. \u0645\u0627\u062d\u0648\u0644\u06cc\u0627\u062a \u06a9\u06cc \u062a\u0631\u062a\u06cc\u0628<\/h2>\n<p>\u0645\u0642\u0627\u0645\u06cc \u0628\u0646\u0627\u0626\u06cc\u06ba <code>.env<\/code> \u0688\u0648\u06cc\u0644\u067e\u0645\u0646\u0679 \u0641\u0627\u0626\u0644\u0648\u06ba \u06a9\u0648 \u0688\u0627\u0624\u0646 \u0644\u0648\u0688 \u06a9\u0631\u06cc\u06ba \u0627\u0648\u0631 \u0627\u0646\u06c1\u06cc\u06ba NestJS \u06a9\u0646\u0641\u06cc\u06af\u0631\u06cc\u0634\u0646 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u0644\u0648\u0688 \u06a9\u0631\u06cc\u06ba\u06d4 \u06cc\u06c1 \u0627\u0642\u062f\u0627\u0631 \u0645\u0642\u0627\u0645\u06cc \u062a\u0631\u062a\u06cc\u0628\u0627\u062a \u06a9\u06cc \u0645\u062b\u0627\u0644 \u06c1\u06cc\u06ba \u0646\u06c1 \u06a9\u06c1 \u067e\u06cc\u062f\u0627\u0648\u0627\u0631 \u06a9\u06d2 \u0631\u0627\u0632\u06d4<\/p>\n<p>\u06a9\u0628\u06be\u06cc \u0628\u06be\u06cc \u0627\u0635\u0644 \u0686\u06cc\u0632 \u06a9\u0627 \u0627\u0631\u062a\u06a9\u0627\u0628 \u0646\u06c1 \u06a9\u0631\u06cc\u06ba\u06d4 <code>.env<\/code> \u0641\u0627\u0626\u0644 \u0639\u0632\u0645 <code>.env.example<\/code> \u0627\u0633 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2\u060c \u06cc\u06c1 \u0635\u0631\u0641 \u0645\u062d\u0641\u0648\u0638 \u067e\u0644\u06cc\u0633 \u06c1\u0648\u0644\u0688\u0631 \u0627\u0642\u062f\u0627\u0631 \u067e\u0631 \u0645\u0634\u062a\u0645\u0644 \u06c1\u06d2\u06d4 \u067e\u0631\u0648\u0688\u06a9\u0634\u0646 \u0645\u06cc\u06ba\u060c \u0627\u06cc\u06a9 \u06c1\u0627\u0626\u06cc \u0627\u06cc\u0646\u0679\u0631\u0648\u067e\u06cc \u0633\u06cc\u06a9\u0631\u06cc\u0679 \u0628\u0646\u0627\u0626\u06cc\u06ba \u0627\u0648\u0631 \u0627\u0633\u06d2 \u0627\u067e\u0646\u06d2 \u06c1\u0648\u0633\u0679\u0646\u06af \u067e\u0644\u06cc\u0679 \u0641\u0627\u0631\u0645 \u06a9\u06d2 \u062e\u0641\u06cc\u06c1 \u0645\u06cc\u0646\u06cc\u062c\u0631 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u06cc\u0627 \u0627\u06cc\u06a9 \u0645\u062d\u0641\u0648\u0638 \u0645\u0627\u062d\u0648\u0644 \u06a9\u0648 \u062a\u0631\u062a\u06cc\u0628 \u062f\u06d2 \u06a9\u0631 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<p>\u0645\u0637\u0644\u0648\u0628\u06c1 \u0645\u062a\u063a\u06cc\u0631\u0627\u062a \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u06a9\u0631\u06cc\u06ba \u062c\u0628 \u0627\u06cc\u067e\u0644\u06cc\u06a9\u06cc\u0634\u0646 \u0627\u0633 \u0628\u0627\u062a \u06a9\u0648 \u06cc\u0642\u06cc\u0646\u06cc \u0628\u0646\u0627\u0646\u0627 \u0634\u0631\u0648\u0639 \u06a9\u0631 \u062f\u06d2 \u06a9\u06c1 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06d2 \u0622\u0646\u06d2 \u062a\u06a9 \u06af\u0645\u0634\u062f\u06c1 \u06cc\u0627 \u062e\u0631\u0627\u0628 \u0631\u0627\u0632 \u06a9\u0648 \u0646\u0638\u0631 \u0627\u0646\u062f\u0627\u0632 \u0646\u06c1 \u06a9\u06cc\u0627 \u062c\u0627\u0626\u06d2\u06d4 \u0627\u0633 \u06a9\u06d2 \u0639\u0644\u0627\u0648\u06c1\u060c \u0627\u067e\u0646\u06cc \u062a\u0631\u062a\u06cc\u0628 \u0627\u0648\u0631 \u0646\u0641\u0627\u0630 \u06a9\u0648 \u0645\u0633\u0644\u0633\u0644 \u0631\u06a9\u06be\u06cc\u06ba\u06d4 <code>ACCESS_TOKEN_EXPIRES_IN<\/code> \u0627\u06af\u0631 \u0642\u0627\u0628\u0644 \u062a\u0631\u062a\u06cc\u0628 \u06c1\u06d2\u060c \u062a\u0648 \u0679\u0648\u06a9\u0646 \u0633\u0631\u0648\u0633 \u06a9\u0648 \u0627\u0633 \u0645\u062a\u063a\u06cc\u0631 \u06a9\u0648 \u06c1\u0627\u0631\u0688 \u06a9\u0648\u0688\u0646\u06af \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2 \u067e\u0691\u06be\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4 <code>'15m'<\/code> \u0622\u067e \u062f\u0633\u062a\u062e\u0637\u06cc \u06a9\u0627\u0644 \u067e\u0631 \u06c1\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-env\">PORT=3000\n\nMONGO_URI=mongodb:\/\/localhost:27017\/secure_auth\n\nREDIS_HOST=localhost\nREDIS_PORT=6379\n\nJWT_ACCESS_SECRET=strong-random-secret\n\nACCESS_TOKEN_EXPIRES_IN=15m\n\nNODE_ENV=development\n<\/code><\/pre>\n<p><code>MONGO_URI<\/code>    MongoDB \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u06a9\u06cc \u0637\u0631\u0641 \u0627\u0634\u0627\u0631\u06c1 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0648\u0631 Redis \u06c1\u0648\u0633\u0679 \u0627\u0648\u0631 \u067e\u0648\u0631\u0679 \u0627\u06cc\u067e\u0644\u06cc \u06a9\u06cc\u0634\u0646 \u06a9\u0648 \u0628\u062a\u0627\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u0634\u0631\u062d \u06a9\u0648 \u0645\u062d\u062f\u0648\u062f \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0645\u0642\u0627\u0635\u062f \u06a9\u06d2 \u0644\u06cc\u06d2 \u06a9\u06c1\u0627\u06ba \u062c\u0691\u0646\u0627 \u06c1\u06d2\u06d4 <code>JWT_ACCESS_SECRET<\/code> \u0686\u0648\u0646\u06a9\u06c1 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646\u0632 \u067e\u0631 \u062f\u0633\u062a\u062e\u0637 \u06a9\u06cc\u06d2 \u06af\u0626\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u0633 \u0644\u06cc\u06d2 \u0648\u06c1 \u063a\u06cc\u0631 \u0645\u062a\u0648\u0642\u0639 \u0627\u0648\u0631 \u0645\u062d\u0641\u0648\u0638 \u06c1\u0648\u0646\u06d2 \u0686\u0627\u06c1\u0626\u06cc\u06ba\u06d4 <code>ACCESS_TOKEN_EXPIRES_IN<\/code> \u0645\u0637\u0644\u0648\u0628\u06c1 \u0645\u062e\u062a\u0635\u0631 \u0639\u0645\u0631 \u06a9\u06cc \u062f\u0633\u062a\u0627\u0648\u06cc\u0632 \u06a9\u0631\u06cc\u06ba\u06d4 \u06cc\u0642\u06cc\u0646\u06cc \u0628\u0646\u0627\u0626\u06cc\u06ba \u06a9\u06c1 \u0622\u067e \u06a9\u0627 \u0639\u0645\u0644 \u062f\u0631\u062d\u0642\u06cc\u0642\u062a \u0627\u0633\u06d2 \u067e\u0691\u06be\u062a\u0627 \u06c1\u06d2\u06d4 <code>NODE_ENV<\/code> \u062a\u0631\u062c\u06cc\u062d\u06cc \u0645\u062e\u0635\u0648\u0635 \u062a\u0631\u062a\u06cc\u0628\u0627\u062a \u06a9\u0648 \u06a9\u0646\u0679\u0631\u0648\u0644 \u06a9\u0631\u06cc\u06ba\u060c \u062c\u06cc\u0633\u06d2 \u06a9\u06c1 \u0622\u06cc\u0627 \u06a9\u0648\u06a9\u06cc\u0632 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u06cc \u062c\u0627\u062a\u06cc \u06c1\u06cc\u06ba \u06cc\u0627 \u0646\u06c1\u06cc\u06ba\u06d4 <code>Secure<\/code> \u06a9\u06cc \u0648\u062c\u06c1 \u0633\u06d2 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u06c1\u0645 \u06c1\u06cc\u06ba <code>JWT_REFRESH_SECRET<\/code> \u06a9\u06cc\u0648\u0646\u06a9\u06c1 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 JWT \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u060c \u06cc\u06c1 \u0627\u06cc\u06a9 \u0645\u062a\u063a\u06cc\u0631 \u06c1\u06d2\u06d4 \u0628\u06d2 \u062a\u0631\u062a\u06cc\u0628 \u0645\u0628\u06c1\u0645 \u0679\u0648\u06a9\u0646\u06d4<\/p>\n<h2 id=\"heading-8-user-model\">8. \u0635\u0627\u0631\u0641 \u06a9\u0627 \u0645\u0627\u0688\u0644<\/h2>\n<p>\u0635\u0627\u0631\u0641\u06cc\u0646 \u06a9\u0648 \u0631\u062c\u0633\u0679\u0631 \u06a9\u0631\u0646\u06d2 \u06cc\u0627 \u0627\u0646 \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2\u060c \u0622\u067e \u06a9\u0648 \u0645\u0639\u0644\u0648\u0645\u0627\u062a \u06a9\u0648 \u0630\u062e\u06cc\u0631\u06c1 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u062c\u06af\u06c1 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2 \u062c\u0648 \u06c1\u0631 \u0627\u06a9\u0627\u0624\u0646\u0679 \u06a9\u06cc \u0634\u0646\u0627\u062e\u062a \u06a9\u0631\u06d2\u06d4 \u0627\u0633 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0645\u06cc\u06ba <code>User<\/code> \u0627\u06cc\u06a9 \u0645\u0627\u0688\u0644 \u0627\u06cc\u06a9 \u0631\u062c\u0633\u0679\u0631\u0688 \u0634\u062e\u0635 \u06a9\u06cc \u0646\u0645\u0627\u0626\u0646\u062f\u06af\u06cc \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0633 \u0645\u06cc\u06ba \u062a\u0635\u062f\u06cc\u0642 \u06a9\u06d2 \u062f\u0648\u0631\u0627\u0646 \u062f\u0631\u06a9\u0627\u0631 \u062a\u0641\u0635\u06cc\u0644\u0627\u062a \u0634\u0627\u0645\u0644 \u06c1\u06cc\u06ba\u060c \u062c\u06cc\u0633\u06d2 \u0627\u06cc \u0645\u06cc\u0644 \u0627\u06cc\u0688\u0631\u06cc\u0633 \u0627\u0648\u0631 \u067e\u0627\u0633 \u0648\u0631\u0688 \u06c1\u06cc\u0634\u060c \u0646\u06cc\u0632 \u0627\u06a9\u0627\u0624\u0646\u0679 \u06a9\u06cc \u0645\u0639\u0644\u0648\u0645\u0627\u062a \u062c\u06cc\u0633\u06d2 \u06a9\u06c1 \u0635\u0627\u0631\u0641 \u0646\u0627\u0645\u060c \u0627\u06cc \u0645\u06cc\u0644 \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u06a9\u06cc \u062d\u06cc\u062b\u06cc\u062a\u060c \u0627\u0648\u0631 \u06a9\u0631\u062f\u0627\u0631\u06d4<\/p>\n<p>\u0622\u0626\u06cc\u06d2 \u0627\u0646 \u06a9\u0631\u062f\u0627\u0631\u0648\u06ba \u06a9\u06cc \u0648\u0636\u0627\u062d\u062a \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 \u0634\u0631\u0648\u0639 \u06a9\u0631\u06cc\u06ba \u062c\u0648 \u0627\u06cc\u067e\u0644\u06cc\u06a9\u06cc\u0634\u0646 \u0633\u0645\u062c\u06be\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-ts\">export enum UserRole {\n  USER = 'user',\n  ADMIN = 'admin',\n  MODERATOR = 'moderator',\n}\n<\/code><\/pre>\n<p>\u0627\u0639\u062f\u0627\u062f \u0648 \u0634\u0645\u0627\u0631 \u0628\u06a9\u06be\u0631\u06d2 \u06c1\u0648\u0626\u06d2 \u062a\u0627\u0631\u0648\u06ba \u06a9\u06cc \u0628\u062c\u0627\u0626\u06d2 \u06a9\u0631\u062f\u0627\u0631 \u06a9\u06cc \u0642\u062f\u0631\u0648\u06ba \u06a9\u0627 \u0627\u06cc\u06a9 \u0645\u0642\u0631\u0631\u06c1 \u0633\u06cc\u0679 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u062c\u06cc\u0633\u06d2: <code>'admin'<\/code> \u0627\u0648\u0631 <code>'user'<\/code> \u067e\u0648\u0631\u06d2 \u06a9\u0648\u0688 \u0645\u06cc\u06ba\u06d4 \u0627\u0633 \u0633\u06d2 \u0631\u0648\u0644 \u0631\u06cc\u0632\u0648\u0644\u0648\u0634\u0646 \u06a9\u0648 \u0645\u0633\u062a\u0642\u0644 \u0631\u06a9\u06be\u0646\u0627 \u0622\u0633\u0627\u0646 \u06c1\u0648 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u06cc\u06c1 \u0627\u0642\u062f\u0627\u0631 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06c1 \u062a\u0641\u0648\u06cc\u0636 \u06a9\u0631\u062f\u06c1 \u0627\u062c\u0627\u0632\u062a\u0648\u06ba \u06a9\u06cc \u0648\u0636\u0627\u062d\u062a \u06a9\u0631\u062a\u06cc \u06c1\u06cc\u06ba\u06d4 \u06cc\u06c1 \u0648\u06c1 \u0627\u0642\u062f\u0627\u0631 \u0646\u06c1\u06cc\u06ba \u06c1\u06cc\u06ba \u062c\u0646\u06c1\u06cc\u06ba \u0627\u0641\u0631\u0627\u062f \u06a9\u06be\u0644\u06d2 \u0627\u0646\u062f\u0631\u0627\u062c \u06a9\u06d2 \u062f\u0648\u0631\u0627\u0646 \u0622\u0632\u0627\u062f\u0627\u0646\u06c1 \u0637\u0648\u0631 \u067e\u0631 \u0645\u0646\u062a\u062e\u0628 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u0627\u06af\u0644\u0627\u060c \u06c1\u0645 \u0627\u067e\u0646\u06d2 \u0635\u0627\u0631\u0641\u06cc\u0646 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u0646\u06af\u0648\u0632 \u0633\u06a9\u06cc\u0645\u0627 \u06a9\u06cc \u0648\u0636\u0627\u062d\u062a \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-ts\">@Schema({ timestamps: true })\nexport class User {\n  @Prop({\n    required: true,\n    unique: true,\n    lowercase: true,\n    trim: true,\n  })\n  email: string;\n\n  @Prop({\n    required: true,\n  })\n  passwordHash: string;\n\n  @Prop({\n    required: true,\n    trim: true,\n  })\n  name: string;\n\n  @Prop({\n    default: false,\n  })\n  emailVerified: boolean;\n\n  @Prop({\n    type: String,\n    enum: Object.values(UserRole),\n    default: UserRole.USER,\n  })\n  role: UserRole;\n}\n\nexport const UserSchema =\n  SchemaFactory.createForClass(User);\n<\/code><\/pre>\n<p>\u06c1\u0631 \u0627\u06cc\u06a9 <code>@Prop()<\/code> \u0688\u06cc\u06a9\u0648\u0631\u06cc\u0679\u0631 \u0645\u0646\u06af\u0648\u0632 \u06a9\u0648 \u0628\u062a\u0627\u062a\u06d2 \u06c1\u06cc\u06ba \u06a9\u06c1 \u06a9\u06be\u06cc\u062a\u0648\u06ba \u06a9\u0648 \u06a9\u06cc\u0633\u06d2 \u0630\u062e\u06cc\u0631\u06c1 \u06a9\u06cc\u0627 \u062c\u0627\u0626\u06d2 \u0627\u0648\u0631 \u0627\u0646 \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u06a9\u06cc \u062c\u0627\u0626\u06d2\u06d4 \u0645\u062b\u0627\u0644 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631\u060c \u0627\u0631\u062f \u06af\u0631\u062f \u06a9\u06cc \u062c\u06af\u06c1\u0648\u06ba \u06a9\u0648 \u06c1\u0679\u0627 \u06a9\u0631 \u0627\u06cc \u0645\u06cc\u0644 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2 \u0627\u0648\u0631 \u0627\u0633\u06d2 \u0686\u06be\u0648\u0679\u06d2 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u0639\u0645\u0648\u0644 \u0628\u0646\u0627\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2\u06d4 \u06a9\u06c1 <code>unique<\/code> \u06cc\u06c1 \u0627\u062e\u062a\u06cc\u0627\u0631 MongoDB \u0633\u06d2 \u0627\u06cc\u06a9 \u0645\u0646\u0641\u0631\u062f \u0627\u0646\u0688\u06cc\u06a9\u0633 \u0628\u0646\u0627\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06a9\u06c1\u062a\u0627 \u06c1\u06d2 \u062a\u0627\u06a9\u06c1 \u06a9\u0648\u0626\u06cc \u0628\u06be\u06cc \u062f\u0648 \u0627\u06a9\u0627\u0624\u0646\u0679\u0633 \u0627\u06cc\u06a9 \u06c1\u06cc \u0627\u06cc \u0645\u06cc\u0644 \u0627\u06cc\u0688\u0631\u06cc\u0633 \u06a9\u0627 \u0627\u0634\u062a\u0631\u0627\u06a9 \u0646\u06c1 \u06a9\u0631 \u0633\u06a9\u06cc\u06ba\u06d4 \u06c1\u0645 \u0627\u0633 \u0628\u0627\u062a \u067e\u0631 \u0628\u062d\u062b \u06a9\u0631\u06cc\u06ba \u06af\u06d2 \u06a9\u06c1 \u0622\u067e \u06a9\u0648 \u0631\u062c\u0633\u0679\u0631\u06cc\u0634\u0646 \u0633\u06cc\u06a9\u0634\u0646 \u06a9\u06d2 \u0630\u06cc\u0644\u06cc \u0633\u06cc\u06a9\u0634\u0646 &quot;\u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u06a9\u06cc \u0631\u06a9\u0627\u0648\u0679\u06cc\u06ba \u0627\u0628\u06be\u06cc \u0628\u06be\u06cc \u062f\u0631\u06a9\u0627\u0631 \u06c1\u06cc\u06ba&#8221; \u0645\u06cc\u06ba \u0688\u067e\u0644\u06cc\u06a9\u06cc\u0679 \u06a9\u0644\u06cc\u062f\u06cc \u063a\u0644\u0637\u06cc\u0648\u06ba \u06a9\u0648 \u06c1\u06cc\u0646\u0688\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06a9\u06cc\u0648\u06ba \u06c1\u06d2\u06d4<\/p>\n<p>\u06a9\u06c1 <code>passwordHash<\/code> \u0641\u06cc\u0644\u0688 \u067e\u0627\u0633 \u0648\u0631\u0688 \u06c1\u06cc\u0634\u0646\u06af \u06a9\u06d2 \u0646\u062a\u06cc\u062c\u06d2 \u06a9\u0648 \u0627\u0633\u0679\u0648\u0631 \u06a9\u0631\u062a\u06cc \u06c1\u06d2\u060c \u0627\u0635\u0644 \u067e\u0627\u0633 \u0648\u0631\u0688 \u06a9\u0648 \u0646\u06c1\u06cc\u06ba\u06d4 <code>name<\/code> \u0645\u0637\u0644\u0648\u0628\u06c1\u060c <code>emailVerified<\/code> \u06cc\u06c1 \u0627\u0633 \u0637\u0631\u062d \u0634\u0631\u0648\u0639 \u06c1\u0648\u062a\u0627 \u06c1\u06d2: <code>false<\/code>\u0627\u0648\u0631 <code>role<\/code> \u067e\u06c1\u0644\u06d2 \u0633\u06d2 \u0637\u06d2 \u0634\u062f\u06c1 \u06c1\u06d2\u06d4 <code>USER<\/code>. \u06a9\u06c1 <code>SchemaFactory<\/code> \u06a9\u0627\u0644 \u0633\u062c\u06d2 \u06c1\u0648\u0626\u06d2 \u0637\u0628\u0642\u06d2 \u06a9\u0648 \u0645\u0648\u0646\u06af\u0648\u0632 \u0627\u0633\u06a9\u06cc\u0645\u0627 \u0645\u06cc\u06ba \u0628\u062f\u0644 \u062f\u06cc\u062a\u06cc \u06c1\u06d2 \u062c\u0648 \u0645\u0627\u0688\u0644 \u0628\u0646\u0627\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<p>\u0645\u0627\u0688\u0644 \u0645\u06cc\u06ba \u06a9\u0648\u0626\u06cc \u062c\u0646\u0631\u06a9 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 <code>password<\/code> \u0645\u06cc\u062f\u0627\u0646 \u06c1\u0645 \u0635\u0631\u0641 \u0631\u06a9\u06be\u062a\u06d2 \u06c1\u06cc\u06ba <code>passwordHash<\/code>\u0627\u0633 \u06a9\u06cc \u0648\u062c\u06c1 \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u0627\u0635\u0644 \u067e\u0627\u0633 \u0648\u0631\u0688 \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u0633\u06d2 \u0628\u0627\u0632\u06cc\u0627\u0641\u062a \u0646\u06c1\u06cc\u06ba \u06c1\u0648\u0646\u0627 \u0686\u0627\u06c1\u0626\u06d2\u06d4<\/p>\n<h2 id=\"heading-9-password-hashing\">9. \u067e\u0627\u0633 \u0648\u0631\u0688 \u06c1\u06cc\u0634 \u06a9\u0631\u0646\u0627<\/h2>\n<p>\u0627\u06af\u0631 \u06a9\u0648\u0626\u06cc \u0622\u067e \u06a9\u06d2 \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u062a\u06a9 \u0631\u0633\u0627\u0626\u06cc \u062d\u0627\u0635\u0644 \u06a9\u0631 \u0644\u06cc\u062a\u0627 \u06c1\u06d2 \u062a\u0648 \u067e\u0627\u0633 \u0648\u0631\u0688 \u06c1\u06cc\u0634\u0646\u06af \u0622\u067e \u06a9\u06cc \u062d\u0641\u0627\u0638\u062a \u06a9\u0631\u062a\u06cc \u06c1\u06d2\u06d4 \u067e\u0627\u0633 \u0648\u0631\u0688 \u06a9\u0648 \u062e\u0648\u062f \u0630\u062e\u06cc\u0631\u06c1 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2\u060c \u0633\u0631\u0648\u0631 \u0627\u06cc\u06a9 \u0637\u0631\u0641\u06c1 \u06c1\u06cc\u0634 \u06a9\u0648 \u0630\u062e\u06cc\u0631\u06c1 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0644\u0627\u06af \u0627\u0646 \u06a9\u06d2 \u062f\u0648\u0631\u0627\u0646\u060c \u0646\u0626\u06d2 \u062c\u0645\u0639 \u06a9\u0631\u0627\u0626\u06d2 \u06af\u0626\u06d2 \u067e\u0627\u0633 \u0648\u0631\u0688 \u06a9\u0648 \u0627\u0633 \u06a9\u06d2 \u06c1\u06cc\u0634 \u0633\u06d2 \u0686\u06cc\u06a9 \u06a9\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u06cc\u067e\u0644\u06cc\u06a9\u06cc\u0634\u0646\u0632 \u06a9\u0648 \u067e\u0627\u0633 \u0648\u0631\u0688 \u0644\u0627\u06af \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2 \u06cc\u0627 API \u062c\u0648\u0627\u0628\u0627\u062a \u0645\u06cc\u06ba \u067e\u0627\u0633 \u0648\u0631\u0688 \u0634\u0627\u0645\u0644 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<p>\u062a\u0635\u0627\u062f\u0641\u06cc \u0637\u0648\u0631 \u067e\u0631 \u0628\u0646\u0627\u0626\u06d2 \u06af\u0626\u06d2 \u067e\u0627\u0633 \u0648\u0631\u0688\u0632 \u06a9\u06d2 \u0645\u0642\u0627\u0628\u0644\u06d2 \u0645\u06cc\u06ba \u0627\u0646\u0633\u0627\u0646\u06cc \u067e\u0627\u0633 \u0648\u0631\u0688\u0632 \u06a9\u0627 \u0627\u0646\u062f\u0627\u0632\u06c1 \u0644\u06af\u0627\u0646\u0627 \u0639\u0645\u0648\u0645\u0627\u064b \u0628\u06c1\u062a \u0622\u0633\u0627\u0646 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4 \u0644\u0648\u06af \u0645\u0627\u0646\u0648\u0633 \u0627\u0644\u0641\u0627\u0638\u060c \u0646\u0627\u0645\u060c \u062a\u0627\u0631\u06cc\u062e\u0648\u06ba \u06cc\u0627 \u0646\u0645\u0648\u0646\u0648\u06ba \u06a9\u0627 \u0627\u0646\u062a\u062e\u0627\u0628 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba \u0627\u0648\u0631 \u062d\u0645\u0644\u06c1 \u0622\u0648\u0631 \u0645\u0645\u06a9\u0646\u06c1 \u067e\u0627\u0633 \u0648\u0631\u0688\u0632 \u06a9\u06cc \u0627\u06cc\u06a9 \u0644\u0645\u0628\u06cc \u0641\u06c1\u0631\u0633\u062a \u0622\u0632\u0645\u0627 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0633\u06cc\u06a9\u0648\u0631\u0679\u06cc \u06a9\u06d2 \u0644\u062d\u0627\u0638 \u0633\u06d2\u060c \u0627\u0633 \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 \u06a9\u06c1 \u067e\u0627\u0633 \u0648\u0631\u0688 \u0627\u06a9\u062b\u0631 \u0646\u0633\u0628\u062a\u0627\u064b \u06a9\u0645\u0632\u0648\u0631 \u06c1\u0648\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 <em>\u0627\u06cc\u0646\u0679\u0631\u0648\u067e\u06cc<\/em>: \u0635\u0631\u0641 \u067e\u0627\u0633 \u0648\u0631\u0688 \u06a9\u06cc \u0644\u0645\u0628\u0627\u0626\u06cc \u06a9\u06cc \u062a\u062c\u0648\u06cc\u0632 \u06a9\u06d2 \u0645\u0642\u0627\u0628\u0644\u06d2 \u0645\u06cc\u06ba \u06a9\u0645 \u0642\u0627\u0628\u0644 \u0641\u06c1\u0645 \u0645\u062c\u0645\u0648\u0639\u06d2 \u06c1\u0648\u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u0627\u0633 \u0644\u06cc\u06d2 \u0622\u067e \u06a9\u0648 \u0627\u067e\u0646\u06d2 \u067e\u0627\u0633 \u0648\u0631\u0688 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0631\u06cc\u06af\u0648\u0644\u0631 SHA-256 \u062c\u06cc\u0633\u06cc \u062a\u06cc\u0632 \u06cc\u0648\u0646\u06cc\u0648\u0631\u0633\u0644 \u06c1\u06cc\u0634\u0632 \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u0686\u0648\u0631\u06cc \u0634\u062f\u06c1 \u067e\u0627\u0633 \u0648\u0631\u0688\u0632 \u06a9\u0627 \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u0631\u06a9\u06be\u0646\u06d2 \u0648\u0627\u0644\u0627 \u062d\u0645\u0644\u06c1 \u0622\u0648\u0631 \u0628\u06c1\u062a \u062c\u0644\u062f \u0627\u0646\u062f\u0627\u0632\u0648\u06ba \u06a9\u06cc \u062c\u0627\u0646\u0686 \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u067e\u0627\u0633 \u0648\u0631\u0688 \u06c1\u06cc\u0634\u0646\u06af \u0627\u0644\u06af\u0648\u0631\u062a\u06be\u0645 \u062c\u06cc\u0633\u06d2 bcrypt \u0627\u0648\u0631 Argon2 \u062c\u0627\u0646 \u0628\u0648\u062c\u06be \u06a9\u0631 \u0645\u06c1\u0646\u06af\u06d2 \u06c1\u06cc\u06ba\u06d4 \u06c1\u0631 \u0627\u0646\u062f\u0627\u0632\u06c1 \u0632\u06cc\u0627\u062f\u06c1 \u0648\u0642\u062a \u0627\u0648\u0631 \u06a9\u0645\u067e\u06cc\u0648\u0679\u06cc\u0634\u0646\u0644 \u0648\u0633\u0627\u0626\u0644 \u0644\u06cc\u062a\u0627 \u06c1\u06d2. \u0627\u0633 \u0645\u06cc\u06ba \u0646\u0645\u06a9 \u0628\u06be\u06cc \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u060c \u0644\u06c1\u0630\u0627 \u0627\u06cc\u06a9 \u06c1\u06cc \u067e\u0627\u0633 \u0648\u0631\u0688 \u06a9\u0627 \u0646\u062a\u06cc\u062c\u06c1 \u0627\u06cc\u06a9 \u06c1\u06cc \u0630\u062e\u06cc\u0631\u06c1 \u0634\u062f\u06c1 \u06c1\u06cc\u0634 \u0645\u06cc\u06ba \u0646\u06c1\u06cc\u06ba \u0622\u0626\u06d2 \u06af\u0627\u06d4 \u06a9\u0645\u0632\u0648\u0631 \u067e\u0627\u0633 \u0648\u0631\u0688\u0632 \u06a9\u0648 \u06a9\u0631\u06cc\u06a9 \u06a9\u0631\u0646\u0627 \u0646\u0627\u0645\u0645\u06a9\u0646 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u060c \u0644\u06cc\u06a9\u0646 \u0628\u0691\u06d2 \u067e\u06cc\u0645\u0627\u0646\u06d2 \u067e\u0631 \u0627\u0646\u062f\u0627\u0632\u06c1 \u0644\u06af\u0627\u0646\u0627 \u0632\u06cc\u0627\u062f\u06c1 \u0645\u06c1\u0646\u06af\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u06cc\u06c1 \u0645\u062b\u0627\u0644 \u062f\u0631\u062c \u0630\u06cc\u0644 \u0644\u0627\u06af\u062a \u06a9\u06d2 \u0639\u0648\u0627\u0645\u0644 \u06a9\u06d2 \u0633\u0627\u062a\u06be bcrypt \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06cc \u06c1\u06d2: <code>12<\/code>:<\/p>\n<pre><code class=\"language-ts\">const passwordHash = await bcrypt.hash(\n  password,\n  12,\n);\n<\/code><\/pre>\n<p>\u062c\u0628 \u06a9\u0648\u0626\u06cc \u0635\u0627\u0631\u0641 \u0644\u0627\u06af \u0627\u0646 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u060c \u062a\u0648 \u06c1\u0645 \u062c\u0645\u0639 \u06a9\u0631\u0627\u0626\u06d2 \u06af\u0626\u06d2 \u067e\u0627\u0633 \u0648\u0631\u0688 \u06a9\u0648 \u0628\u0631\u0627\u06c1 \u0631\u0627\u0633\u062a \u06c1\u06cc\u0634 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2 \u062f\u0648 \u062a\u0627\u0631\u0648\u06ba \u06a9\u0627 \u0645\u0648\u0627\u0632\u0646\u06c1 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 Bcrypt \u0627\u0646\u06a9\u0648\u0688 \u0634\u062f\u06c1 \u06c1\u06cc\u0634 \u06a9\u06d2 \u062d\u0635\u06d2 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0646\u0645\u06a9 \u0627\u0648\u0631 \u0642\u06cc\u0645\u062a \u06a9\u06cc \u0645\u0639\u0644\u0648\u0645\u0627\u062a \u06a9\u0648 \u0627\u0633\u0679\u0648\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 <code>compare()<\/code> \u06c1\u0645 \u0627\u0633 \u0645\u0639\u0644\u0648\u0645\u0627\u062a \u06a9\u0648 \u0645\u0646\u0627\u0633\u0628 \u062a\u0635\u062f\u06cc\u0642\u06cc \u0639\u0645\u0644 \u06a9\u0648 \u0686\u0644\u0627\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u06cc\u06ba \u06af\u06d2\u06d4<\/p>\n<pre><code class=\"language-ts\">const valid = await bcrypt.compare(\n  password,\n  user.passwordHash,\n);\n<\/code><\/pre>\n<p>\u0628\u0631\u0627\u06c1 \u0631\u0627\u0633\u062a \u0645\u0648\u0627\u0632\u0646\u06c1 \u062c\u06cc\u0633\u06d2: <code>password === passwordHash<\/code> \u062c\u0645\u0639 \u06a9\u0631\u0627\u06cc\u0627 \u06af\u06cc\u0627 \u067e\u0627\u0633 \u0648\u0631\u0688 \u06a9\u0627\u0645 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u06d2 \u06af\u0627 \u06a9\u06cc\u0648\u0646\u06a9\u06c1 \u06cc\u06c1 \u0633\u0627\u062f\u06c1 \u0645\u062a\u0646 \u06c1\u06d2\u06d4 <code>passwordHash<\/code> \u0627\u06cc\u06a9 \u0646\u0645\u06a9\u06cc\u0646 \u0627\u0646\u06a9\u0648\u0688 \u0634\u062f\u06c1 \u06c1\u06cc\u0634\u06d4 \u0642\u062f\u0631\u06cc\u06ba \u0645\u062e\u062a\u0644\u0641 \u06c1\u06cc\u06ba \u0627\u0648\u0631 \u0645\u062d\u0641\u0648\u0638 \u067e\u0627\u0633 \u0648\u0631\u0688 \u06c1\u06cc\u0634\u0632 \u06a9\u0648 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0688\u06cc\u0632\u0627\u0626\u0646 \u0646\u06c1\u06cc\u06ba \u06a9\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2\u06d4 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u06cc\u06ba <code>bcrypt.compare()<\/code> \u0644\u06c1\u0630\u0627 \u0644\u0627\u0626\u0628\u0631\u06cc\u0631\u06cc \u06c1\u06cc\u0634 \u0645\u06cc\u06ba \u0630\u062e\u06cc\u0631\u06c1 \u0634\u062f\u06c1 \u0646\u0645\u06a9 \u0627\u0648\u0631 \u067e\u06cc\u0631\u0627\u0645\u06cc\u0679\u0631\u0632 \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 \u067e\u0627\u0633 \u0648\u0631\u0688 \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0631 \u0633\u06a9\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<p>\u0627\u0633 \u06a9\u06d2 \u0639\u0644\u0627\u0648\u06c1\u060c \u067e\u0627\u0633 \u0648\u0631\u0688 \u06c1\u06cc\u0634\u0646\u06af \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2 \u0627\u0646\u06a9\u0631\u067e\u0634\u0646 \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u0646\u06c1 \u06a9\u0631\u06cc\u06ba\u06d4 \u0627\u0646\u06a9\u0631\u067e\u0634\u0646 \u06a9\u0648 \u0627\u0633 \u0644\u06cc\u06d2 \u0688\u06cc\u0632\u0627\u0626\u0646 \u06a9\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2 \u06a9\u06c1 \u0627\u06cc\u06a9 \u0628\u0627\u0631 \u0622\u067e \u06a9\u06d2 \u067e\u0627\u0633 \u06a9\u0644\u06cc\u062f \u06c1\u0648 \u062c\u0627\u0626\u06d2\u060c \u0627\u0648\u0631 \u0627\u06cc\u067e\u0644\u06cc\u06a9\u06cc\u0634\u0646 \u06a9\u0648 \u06a9\u0628\u06be\u06cc \u0628\u06be\u06cc \u0635\u0627\u0631\u0641 \u06a9\u06d2 \u067e\u0627\u0633 \u0648\u0631\u0688 \u06a9\u0648 \u0688\u06a9\u0631\u067e\u0679 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u067e\u0627\u0633 \u0648\u0631\u0688 \u06c1\u06cc\u0634\u0632 \u06a9\u0648 \u0627\u0633\u0679\u0648\u0631 \u06a9\u0631\u06cc\u06ba \u0627\u0648\u0631 \u0635\u0627\u0631\u0641\u06cc\u0646 \u06a9\u06d2 \u0644\u0627\u06af \u0627\u0646 \u06c1\u0648\u0646\u06d2 \u067e\u0631 \u0627\u0646\u06c1\u06cc\u06ba \u0686\u06cc\u06a9 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<h2 id=\"heading-10-registration\">10. \u0631\u062c\u0633\u0679\u0631\u06cc\u0634\u0646<\/h2>\n<p>\u0631\u062c\u0633\u0679\u0631\u06cc\u0634\u0646 \u0648\u06c1 \u067e\u06c1\u0644\u06cc \u062c\u06af\u06c1 \u06c1\u06d2 \u062c\u06c1\u0627\u06ba \u0646\u0627\u0645\u0639\u0644\u0648\u0645 \u06a9\u0644\u0627\u0626\u0646\u0679\u0633 \u06a9\u0627 \u0688\u06cc\u0679\u0627 \u06c1\u0645\u0627\u0631\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0645\u06cc\u06ba \u062f\u0627\u062e\u0644 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4 \u0622\u067e \u06a9\u0648 \u0627\u0633 \u0688\u06cc\u0679\u0627 \u06a9\u0648 \u0628\u0631\u0627\u06c1 \u0631\u0627\u0633\u062a \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u0622\u067e\u0631\u06cc\u0634\u0646\u0632 \u0645\u06cc\u06ba \u0645\u0646\u062a\u0642\u0644 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u0633\u0628 \u0633\u06d2 \u067e\u06c1\u0644\u06d2\u060c \u06c1\u0645\u06cc\u06ba \u06cc\u06c1 \u0686\u06cc\u06a9 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2 \u06a9\u06c1 \u0622\u06cc\u0627 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0645\u06cc\u06ba \u0648\u06c1 \u0641\u06cc\u0644\u0688\u0632 \u0634\u0627\u0645\u0644 \u06c1\u06cc\u06ba \u062c\u0646 \u06a9\u06cc \u06c1\u0645 \u062a\u0648\u0642\u0639 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba \u0627\u0648\u0631 \u0622\u06cc\u0627 \u0627\u0646 \u0641\u06cc\u0644\u0688\u0632 \u06a9\u06cc \u0645\u0646\u0627\u0633\u0628 \u0642\u062f\u0631\u06cc\u06ba \u06c1\u06cc\u06ba\u06d4 \u0627\u0633 \u06a9\u06d2 \u0628\u0639\u062f \u0622\u067e \u06a9\u0648 \u0635\u0627\u0631\u0641 \u06a9\u06d2 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u0645\u06cc\u06ba \u0648\u0627\u0636\u062d \u0637\u0648\u0631 \u067e\u0631 \u0627\u062c\u0627\u0632\u062a \u0634\u062f\u06c1 \u0627\u0642\u062f\u0627\u0631 \u06a9\u0627 \u0646\u0642\u0634\u06c1 \u0628\u0646\u0627\u0646\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2\u06d4<\/p>\n<p>NestJS \u0645\u06cc\u06ba <strong>\u0688\u06cc\u0679\u0627 \u0679\u0631\u0627\u0646\u0633\u0641\u0631 \u0622\u0628\u062c\u06cc\u06a9\u0679 (DTO)<\/strong> \u0688\u06cc\u0679\u0627 \u06a9\u06cc \u0642\u0633\u0645 \u06a9\u06cc \u0648\u0636\u0627\u062d\u062a \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u062c\u0633 \u06a9\u0648 \u0627\u062e\u062a\u062a\u0627\u0645\u06cc \u0646\u0642\u0637\u06c1 \u0642\u0628\u0648\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u06cc\u0627 \u0648\u0627\u067e\u0633 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0631\u062c\u0633\u0679\u0631\u06cc\u0634\u0646 \u06a9\u06d2 \u0644\u06cc\u06d2\u060c \u0688\u06cc \u0679\u06cc \u0627\u0648 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06cc \u0628\u0627\u0688\u06cc \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u0645\u0639\u0627\u06c1\u062f\u06c1 \u06c1\u06d2\u06d4 \u06c1\u0645 \u0688\u06cc\u06a9\u0648\u0631\u06cc\u0679\u0631 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 <code>class-validator<\/code> &quot;\u06cc\u06c1 \u0642\u062f\u0631 \u0627\u06cc\u06a9 \u0627\u06cc \u0645\u06cc\u0644 \u067e\u062a\u06c1 \u06c1\u0648\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4&#8221; \u06cc\u0627 &quot;\u067e\u0627\u0633 \u0648\u0631\u0688\u0632 8 \u0633\u06d2 128 \u062d\u0631\u0648\u0641 \u06a9\u06d2 \u062f\u0631\u0645\u06cc\u0627\u0646 \u06c1\u0648\u0646\u06d2 \u0686\u0627\u06c1\u0626\u06cc\u06ba\u06d4&#8221; NestJS \u06a9\u0627 <code>ValidationPipe<\/code> \u06a9\u0646\u0679\u0631\u0648\u0644\u0631 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u067e\u0631 \u06a9\u0627\u0631\u0631\u0648\u0627\u0626\u06cc \u06a9\u0631\u0646\u06d2 \u0633\u06d2 \u067e\u06c1\u0644\u06d2 \u06cc\u06c1 \u0686\u06cc\u06a9 \u0686\u0644\u0627\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0631\u062c\u0633\u0679\u0631\u0688 \u0688\u06cc \u0679\u06cc \u0627\u0648 \u0645\u0646\u062f\u0631\u062c\u06c1 \u0630\u06cc\u0644 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-ts\">export class RegisterDto {\n  @IsEmail()\n  email: string;\n\n  @IsString()\n  @MinLength(8)\n  @MaxLength(128)\n  password: string;\n\n  @IsString()\n  @MinLength(2)\n  @MaxLength(100)\n  name: string;\n}\n<\/code><\/pre>\n<p>\u0639\u0627\u0644\u0645\u06cc \u0633\u0637\u062d \u067e\u0631 \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0648 \u0641\u0639\u0627\u0644 \u06a9\u0631\u06cc\u06ba:<\/p>\n<pre><code class=\"language-ts\">app.useGlobalPipes(\n  new ValidationPipe({\n    whitelist: true,\n    forbidNonWhitelisted: true,\n    transform: true,\n  }),\n);\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u0627\u06c1\u0645 \u06c1\u06d2 \u06a9\u06cc\u0648\u0646\u06a9\u06c1 \u062d\u0645\u0644\u06c1 \u0622\u0648\u0631 \u0628\u06be\u06cc\u062c \u0633\u06a9\u062a\u0627 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-json\">{\n  \"email\": \"user@example.com\",\n  \"password\": \"password\",\n  \"role\": \"admin\"\n}\n<\/code><\/pre>\n<p>\u0627\u062d\u062a\u06cc\u0627\u0637 <code>role<\/code> \u06a9\u0627 \u062d\u0635\u06c1 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2 <code>RegisterDto<\/code>. \u06cc\u06c1 \u062c\u0627\u0646 \u0628\u0648\u062c\u06be \u06a9\u0631 \u06c1\u06d2\u06d4 \u0639\u0648\u0627\u0645\u06cc \u0631\u062c\u0633\u0679\u0631\u06cc\u0634\u0646 \u06a9\u06d2 \u0627\u062e\u062a\u062a\u0627\u0645\u06cc \u0646\u0642\u0637\u06c1 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06a9\u0633\u06cc \u06a9\u0648 \u0627\u067e\u0646\u0627 \u0627\u06cc \u0645\u06cc\u0644\u060c \u067e\u0627\u0633 \u0648\u0631\u0688 \u0627\u0648\u0631 \u0646\u0627\u0645 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0642\u0627\u0628\u0644 \u06c1\u0648\u0646\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u060c \u0644\u06cc\u06a9\u0646 \u06cc\u06c1 \u062a\u0639\u06cc\u0646 \u0646\u06c1\u06cc\u06ba \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u06a9\u06c1 \u0622\u06cc\u0627 \u0648\u06c1 \u0628\u0627\u0642\u0627\u0639\u062f\u06c1 \u0635\u0627\u0631\u0641\u060c \u0646\u0627\u0638\u0645 \u06cc\u0627 \u0645\u0646\u062a\u0638\u0645 \u06c1\u06cc\u06ba\u06d4 \u0635\u0627\u0631\u0641 \u0645\u0627\u0688\u0644 \u06a9\u0627 \u0627\u06cc\u06a9 \u0688\u06cc\u0641\u0627\u0644\u0679 \u0631\u0648\u0644 \u06c1\u0648\u062a\u0627 \u06c1\u06d2 (<code>USER<\/code>) \u0633\u0631\u0648\u0631 \u067e\u0631\u06d4<\/p>\n<p>\u06a9\u06cc\u0648\u0646\u06a9\u06c1 \u06c1\u0645 \u0646\u06d2 \u0641\u0639\u0627\u0644 \u06a9\u06cc\u0627\u06d4 <code>whitelist<\/code> \u0627\u0648\u0631 <code>forbidNonWhitelisted<\/code>NestJS \u0627\u06cc\u0633\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u0648 \u0645\u0633\u062a\u0631\u062f \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u062c\u0646 \u0645\u06cc\u06ba \u0688\u06cc \u0679\u06cc \u0627\u0648 \u0645\u06cc\u06ba \u0627\u0639\u0644\u0627\u0646 \u06a9\u0631\u062f\u06c1 \u067e\u0631\u0627\u067e\u0631\u0679\u06cc\u0632 \u0634\u0627\u0645\u0644 \u0646\u06c1\u06cc\u06ba \u06c1\u06cc\u06ba\u06d4 \u0645\u062b\u0627\u0644 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631\u060c \u0634\u0627\u0645\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u06a9\u0648\u0634\u0634 \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a <code>\"role\": \"admin\"<\/code> \u0627\u0633 \u067e\u0631\u0627\u067e\u0631\u0679\u06cc \u06a9\u0648 \u062e\u0648\u062f \u0628\u062e\u0648\u062f \u067e\u0627\u0633 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2\u060c \u06cc\u06c1 \u062a\u0648\u062b\u06cc\u0642 \u0645\u06cc\u06ba \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u06a9\u0646\u0679\u0631\u0648\u0644\u0631\u0632 \u06a9\u0648 \u0686\u0627\u06c1\u06cc\u06d2 \u06a9\u06c1 \u0648\u06c1 \u0635\u0627\u0631\u0641 \u06a9\u0648 \u0627\u062c\u0627\u0632\u062a \u0634\u062f\u06c1 \u0641\u06cc\u0644\u0688\u0632 \u06a9\u06cc \u0627\u06cc\u06a9 \u0648\u0627\u0636\u062d \u0641\u06c1\u0631\u0633\u062a \u0633\u06d2 \u062a\u062e\u0644\u06cc\u0642 \u06a9\u0631\u06cc\u06ba \u0628\u062c\u0627\u0626\u06d2 \u0627\u0633 \u06a9\u06d2 \u06a9\u06c1 \u067e\u0648\u0631\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0622\u0628\u062c\u06cc\u06a9\u0679 \u06a9\u0648 \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u062f\u0633\u062a\u0627\u0648\u06cc\u0632\u0627\u062a \u0645\u06cc\u06ba \u067e\u06be\u06cc\u0644\u0627 \u062f\u06cc\u06ba\u06d4<\/p>\n<p>\u0644\u06c1\u0630\u0627 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0627\u0633 \u0631\u0627\u0633\u062a\u06d2 \u06a9\u06cc \u067e\u06cc\u0631\u0648\u06cc \u06a9\u0631\u062a\u06cc \u06c1\u06d2:<\/p>\n<pre><code class=\"language-text\">Client sends registration data\n          \u2193\nValidationPipe checks the DTO\n          \u2193\nKnown, valid fields reach the controller\n          \u2193\nController\/service maps allowed fields\n          \u2193\nUser is created with the server-side default role\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u062e\u0637\u0631\u06c1 \u06a9\u0645 \u06a9\u0631\u0646\u06d2 \u06a9\u0627 \u0627\u06cc\u06a9 \u0637\u0631\u06cc\u0642\u06c1 \u06c1\u06d2\u06d4 <strong>\u0628\u0644\u06a9 \u0645\u062e\u062a\u0635<\/strong>: \u0646\u0627\u062f\u0627\u0646\u0633\u062a\u06c1 \u0637\u0648\u0631 \u067e\u0631 \u06a9\u0644\u0627\u0626\u0646\u0679 \u06a9\u0648 \u0627\u0646\u062f\u0631\u0648\u0646\u06cc \u0641\u06cc\u0644\u0688\u0632 \u0633\u06cc\u0679 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u0646\u0627 \u062c\u0648 \u0635\u0631\u0641 \u0633\u0631\u0648\u0631 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u06a9\u0646\u0679\u0631\u0648\u0644 \u06a9\u06cc\u0627 \u062c\u0627\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<h3 id=\"heading-database-constraints-are-still-required\">\u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u06a9\u06cc \u067e\u0627\u0628\u0646\u062f\u06cc\u0627\u06ba \u0627\u0628\u06be\u06cc \u0628\u06be\u06cc \u062f\u0631\u06a9\u0627\u0631 \u06c1\u06cc\u06ba\u06d4<\/h3>\n<p>\u0627\u06a9\u0627\u0624\u0646\u0679 \u0628\u0646\u0627\u0646\u06d2 \u0633\u06d2 \u067e\u06c1\u0644\u06d2\u060c \u06cc\u06c1 \u0686\u06cc\u06a9 \u06a9\u0631\u0646\u0627 \u0645\u0641\u06cc\u062f \u06c1\u0648 \u0633\u06a9\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u0622\u06cc\u0627 \u0622\u067e \u06a9\u0627 \u0627\u06cc \u0645\u06cc\u0644 \u0627\u06cc\u0688\u0631\u06cc\u0633 \u067e\u06c1\u0644\u06d2 \u0633\u06d2 \u0631\u062c\u0633\u0679\u0631\u0688 \u06c1\u06d2\u06d4 \u06cc\u06c1 API \u06a9\u0648 \u0639\u0627\u0645 \u0635\u0648\u0631\u062a \u0645\u06cc\u06ba \u062f\u0648\u0633\u062a\u0627\u0646\u06c1 \u062c\u0648\u0627\u0628\u0627\u062a \u0648\u0627\u067e\u0633 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4 \u062a\u0627\u06c1\u0645\u060c \u06cc\u06c1 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06cc \u0633\u0637\u062d \u06a9\u06cc \u062c\u0627\u0646\u0686 \u0635\u0631\u0641 \u0633\u06c1\u0648\u0644\u062a \u06a9\u06d2 \u0644\u06cc\u06d2 \u06c1\u06d2\u06d4 \u0627\u06af\u0631 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u0628\u06cc\u06a9 \u0648\u0642\u062a \u067e\u06c1\u0646\u0686 \u062c\u0627\u0626\u06cc\u06ba \u062a\u0648 \u0627\u0646\u0641\u0631\u0627\u062f\u06cc\u062a \u06a9\u06cc \u0636\u0645\u0627\u0646\u062a \u0646\u06c1\u06cc\u06ba \u062f\u06cc \u062c\u0627 \u0633\u06a9\u062a\u06cc\u06d4<\/p>\n<p>\u0645\u062b\u0627\u0644 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631\u060c \u0631\u062c\u0633\u0679\u0631\u06cc\u0634\u0646 \u06a9\u06cc \u062f\u0648 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u062f\u0648\u0646\u0648\u06ba \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u06a9\u0648 \u0686\u06cc\u06a9 \u06a9\u0631 \u0633\u06a9\u062a\u06cc \u06c1\u06cc\u06ba \u0627\u0633 \u0633\u06d2 \u067e\u06c1\u0644\u06d2 \u06a9\u06c1 \u0627\u0646 \u0645\u06cc\u06ba \u0633\u06d2 \u06a9\u0648\u0626\u06cc \u0627\u06cc\u06a9 \u0646\u06cc\u0627 \u0635\u0627\u0631\u0641 \u062f\u0627\u062e\u0644 \u06a9\u0631\u06d2\u06d4 \u062f\u0648\u0646\u0648\u06ba \u062a\u0635\u062f\u06cc\u0642\u0627\u062a \u06a9\u06cc \u0627\u0637\u0644\u0627\u0639 \u06c1\u06d2 \u06a9\u06c1 \u0622\u067e \u06a9\u0627 \u0627\u06cc \u0645\u06cc\u0644 \u062f\u0633\u062a\u06cc\u0627\u0628 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u067e\u06be\u0631 \u062f\u0648\u0646\u0648\u06ba \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u0627\u06a9\u0627\u0624\u0646\u0679 \u0628\u0646\u0627\u0646\u06d2 \u06a9\u06cc \u06a9\u0648\u0634\u0634 \u06a9\u0631 \u0633\u06a9\u062a\u06cc \u06c1\u06cc\u06ba\u06d4 MongoDB \u0645\u06cc\u06ba \u0645\u0646\u0641\u0631\u062f \u0627\u0646\u0688\u06cc\u06a9\u0633 \u0688\u067e\u0644\u06cc\u06a9\u06cc\u0679 \u0631\u06cc\u06a9\u0627\u0631\u0688\u0632 \u06a9\u0648 \u0630\u062e\u06cc\u0631\u06c1 \u06c1\u0648\u0646\u06d2 \u0633\u06d2 \u0631\u0648\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u0622\u067e \u0627\u0628 \u0628\u06be\u06cc \u0627\u0628\u062a\u062f\u0627\u0626\u06cc \u0627\u0646\u06a9\u0648\u0627\u0626\u0631\u06cc \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-ts\">const existing =\n  await usersService.findByEmail(email);\n<\/code><\/pre>\n<p>\u0644\u06cc\u06a9\u0646 \u06cc\u06c1 \u0627\u06a9\u06cc\u0644\u0627 \u06a9\u0627\u0641\u06cc \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4<\/p>\n<p>\u062f\u0648 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u0628\u06cc\u06a9 \u0648\u0642\u062a \u067e\u06c1\u0646\u0686 \u0633\u06a9\u062a\u06cc \u06c1\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-text\">Request A \u2192 email doesn't exist\nRequest B \u2192 email doesn't exist\n<\/code><\/pre>\n<p>\u0627\u0648\u0631 \u0622\u067e \u062f\u0648\u0646\u0648\u06ba \u0627\u06cc\u06a9 \u0627\u06a9\u0627\u0624\u0646\u0679 \u0628\u0646\u0627\u0646\u06d2 \u06a9\u06cc \u06a9\u0648\u0634\u0634 \u0628\u06be\u06cc \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u0644\u06c1\u0630\u0627\u060c \u0627\u0633\u06a9\u06cc\u0645\u0627 \u06a9\u0648 \u0627\u06cc \u0645\u06cc\u0644 \u0641\u06cc\u0644\u0688 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u0645\u0646\u0641\u0631\u062f \u0627\u0646\u0688\u06cc\u06a9\u0633 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-ts\">unique: true\n<\/code><\/pre>\n<p>\u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u0627\u0646\u0688\u06cc\u06a9\u0633 \u0631\u06cc\u0633 \u06a9\u06d2 \u062d\u0627\u0644\u0627\u062a \u06a9\u0648 \u0633\u0646\u0628\u06be\u0627\u0644\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0627\u06af\u0631 \u062f\u0648\u0646\u0648\u06ba \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u067e\u0686\u06be\u0644\u06cc \u062a\u0644\u0627\u0634 \u06a9\u0648 \u067e\u0627\u0633 \u06a9\u0631\u062a\u06cc \u06c1\u06cc\u06ba\u060c \u062a\u0648 MongoDB \u067e\u06c1\u0644\u06d2 \u062f\u0627\u062e\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06d2 \u06af\u0627 \u0627\u0648\u0631 \u062f\u0648\u0633\u0631\u06cc \u06a9\u0648 \u0688\u067e\u0644\u06cc\u06a9\u06cc\u0679 \u06a9\u0644\u06cc\u062f \u06a9\u06cc \u062e\u0631\u0627\u0628\u06cc (\u0639\u0627\u0645 \u0637\u0648\u0631 \u067e\u0631 \u0627\u06cc\u06a9 \u0627\u06cc\u0631\u0631 \u06a9\u0648\u0688) \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0645\u0633\u062a\u0631\u062f \u06a9\u0631 \u062f\u06d2 \u06af\u0627\u06d4 <code>11000<\/code>)\u06d4<\/p>\n<p>\u0631\u062c\u0633\u0679\u0631\u06cc\u0634\u0646 \u0633\u0631\u0648\u0633 \u0627\u06cc\u067e\u0644\u06cc\u06a9\u06cc\u0634\u0646 \u06a9\u0627 \u0648\u06c1 \u062d\u0635\u06c1 \u06c1\u06d2 \u062c\u0633\u06d2 \u0627\u067e\u0646\u06d2 \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u06a9\u06cc \u063a\u0644\u0637\u06cc\u0648\u06ba \u06a9\u0648 \u067e\u06a9\u0691\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u0633\u06d2 \u0645\u062a\u0639\u0644\u0642 \u063a\u0644\u0637\u06cc\u0648\u06ba \u06a9\u0627 \u062a\u0631\u062c\u0645\u06c1 \u0645\u0646\u062f\u0631\u062c\u06c1 \u0630\u06cc\u0644 \u06a9\u06cc \u0637\u0631\u062d \u0645\u062a\u0648\u0642\u0639 HTTP \u062c\u0648\u0627\u0628\u0627\u062a \u0645\u06cc\u06ba \u06a9\u06cc\u0627 \u062c\u0627 \u0633\u06a9\u062a\u0627 \u06c1\u06d2: <code>409 Conflict<\/code>\u0645\u0648\u0646\u06af\u0648 \u0688\u06cc \u0628\u06cc \u06a9\u06cc \u062e\u0627\u0645 \u062a\u0641\u0635\u06cc\u0644\u0627\u062a \u06a9\u0644\u0627\u0626\u0646\u0679 \u06a9\u06d2 \u0633\u0627\u0645\u0646\u06d2 \u0644\u0627\u0626\u06d2 \u0628\u063a\u06cc\u0631\u06d4 \u0645\u062b\u0627\u0644 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631:<\/p>\n<pre><code class=\"language-ts\">try {\n  return await this.usersService.create({\n    email,\n    passwordHash,\n    name,\n  });\n} catch (error) {\n  if (\n    error &&\n    typeof error === 'object' &&\n    'code' in error &&\n    error.code === 11000\n  ) {\n    throw new ConflictException(\n      'An account with this email already exists',\n    );\n  }\n\n  throw error;\n}\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u0627\u06cc\u06a9 \u0645\u062b\u0627\u0644 \u06c1\u06d2\u06d4 <code>try\/catch<\/code> \u0686\u0627\u06c1\u06d2 \u06cc\u06c1 \u0627\u0633 \u0639\u0645\u0644 \u06a9\u06d2 \u0622\u0633 \u067e\u0627\u0633 \u06c1\u06d2 \u062c\u0648 \u062f\u0631\u062d\u0642\u06cc\u0642\u062a \u062f\u0627\u062e\u0644 \u06a9\u0648 \u0627\u0646\u062c\u0627\u0645 \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4 <code>AuthService<\/code> \u06cc\u0627 <code>UsersService<\/code> \u0622\u067e \u06a9\u06d2 \u0645\u0646\u0635\u0648\u0628\u06d2 \u0645\u06cc\u06ba. \u0627\u06c1\u0645 \u062d\u0635\u06c1 \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u062c\u0628 \u062f\u0631\u062c\u06c1 \u0628\u0646\u062f\u06cc \u06a9\u06cc \u067e\u0631\u0648\u0633\u06cc\u0633\u0646\u06af \u0627\u06a9\u0627\u0624\u0646\u0679 \u06a9\u06cc \u062a\u062e\u0644\u06cc\u0642 \u0688\u067e\u0644\u06cc\u06a9\u06cc\u0679 \u06a9\u0644\u06cc\u062f\u06cc \u063a\u0644\u0637\u06cc\u0648\u06ba \u06a9\u0648 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u062a\u06cc \u06c1\u06d2\u060c \u063a\u06cc\u0631 \u0645\u062a\u0648\u0642\u0639 \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u06a9\u06cc \u063a\u0644\u0637\u06cc\u0627\u06ba \u0627\u0628 \u0628\u06be\u06cc \u0627\u06cc\u067e\u0644\u06cc \u06a9\u06cc\u0634\u0646 \u06a9\u06d2 \u0628\u0627\u0642\u0627\u0639\u062f\u06c1 \u0627\u06cc\u0631\u0631 \u06c1\u06cc\u0646\u0688\u0644\u0646\u06af \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u06c1\u06cc\u0646\u0688\u0644 \u06a9\u06cc \u062c\u0627\u062a\u06cc \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u0627\u0628\u062a\u062f\u0627\u0626\u06cc \u062a\u0644\u0627\u0634 \u0635\u0627\u0631\u0641 \u06a9\u06d2 \u062a\u062c\u0631\u0628\u06d2 \u06a9\u0648 \u0628\u06c1\u062a\u0631 \u0628\u0646\u0627\u062a\u06cc \u06c1\u06d2\u060c \u0645\u0646\u0641\u0631\u062f \u0627\u0646\u0688\u06cc\u06a9\u0633 \u0688\u06cc\u0679\u0627 \u06a9\u06cc \u0631\u06a9\u0627\u0648\u0679\u0648\u06ba \u06a9\u0648 \u06cc\u0642\u06cc\u0646\u06cc \u0628\u0646\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u0648\u0631 \u0633\u0631\u0648\u0633 \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u06a9\u06cc \u063a\u0644\u0637\u06cc\u0648\u06ba \u06a9\u0648 \u0645\u062d\u0641\u0648\u0638 API \u062c\u0648\u0627\u0628\u0627\u062a \u0645\u06cc\u06ba \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u062a\u06cc \u06c1\u06d2\u06d4 \u06c1\u0631 \u0627\u06cc\u06a9 \u06a9\u0627 \u0627\u0644\u06af \u06a9\u0627\u0645 \u06c1\u06d2\u06d4<\/p>\n<h2 id=\"heading-11-sessions\">11. \u0633\u06cc\u0634\u0646<\/h2>\n<p>\u0627\u06cc\u06a9 \u0633\u06cc\u0634\u0646 \u0627\u06cc\u06a9 \u0648\u0627\u062d\u062f \u062a\u0635\u062f\u06cc\u0642 \u0634\u062f\u06c1 \u0644\u0627\u06af \u0627\u0646 \u0633\u06cc\u0627\u0642 \u0648 \u0633\u0628\u0627\u0642 \u06a9\u06cc \u0646\u0645\u0627\u0626\u0646\u062f\u06af\u06cc \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u062c\u06cc\u0633\u06d2 \u0644\u06cc\u067e \u0679\u0627\u067e \u06cc\u0627 \u0645\u0648\u0628\u0627\u0626\u0644 \u0641\u0648\u0646 \u067e\u0631 \u0628\u0631\u0627\u0624\u0632\u0631\u06d4 \u0635\u0627\u0631\u0641 \u06a9\u06cc \u062a\u0627\u0631\u06cc\u062e \u0633\u06d2 \u0627\u0644\u06af \u0633\u06cc\u0634\u0646 \u06a9\u06cc \u062d\u0627\u0644\u062a \u06a9\u0648 \u0628\u0631\u0642\u0631\u0627\u0631 \u0631\u06a9\u06be\u0646\u06d2 \u0633\u06d2 \u0622\u067e \u06a9\u0648 \u0622\u0644\u06c1\u060c \u0622\u062e\u0631\u06cc \u0633\u0631\u06af\u0631\u0645\u06cc\u060c \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648\u0646\u06d2 \u0627\u0648\u0631 \u062e\u062a\u0645 \u06c1\u0648\u0646\u06d2 \u06a9\u0627 \u067e\u062a\u06c1 \u0644\u06af\u0627\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u0645\u0644\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<p>\u0628\u06c1\u062a\u0631 \u06c1\u06d2 \u06a9\u06c1 \u0627\u0646 \u062a\u0635\u0648\u0631\u0627\u062a \u06a9\u0648 \u0627\u0644\u06af \u0631\u06a9\u06be\u0627 \u062c\u0627\u0626\u06d2\u06d4 \u0635\u0627\u0631\u0641 \u0627\u06cc\u06a9 \u0627\u06a9\u0627\u0624\u0646\u0679 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u0627\u06cc\u06a9 \u0633\u06cc\u0634\u0646 \u0627\u0633 \u0627\u06a9\u0627\u0624\u0646\u0679 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u0641\u0639\u0627\u0644 \u0644\u0627\u06af \u0627\u0646 \u06a9\u06cc \u0646\u0645\u0627\u0626\u0646\u062f\u06af\u06cc \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u06cc\u06a9 \u0635\u0627\u0631\u0641 \u0645\u062a\u0639\u062f\u062f \u0622\u0644\u0627\u062a \u06cc\u0627 \u0628\u0631\u0627\u0624\u0632\u0631\u0632 \u0633\u06d2 \u0628\u06cc\u06a9 \u0648\u0642\u062a \u0644\u0627\u06af \u0627\u0646 \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 \u0645\u062b\u0627\u0644 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631\u060c \u0627\u06cc\u06a9 \u06c1\u06cc \u0627\u06a9\u0627\u0624\u0646\u0679 \u06a9\u06d2 \u0633\u06cc\u0634\u0646 \u06c1\u0648 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-text\">Laptop\nPhone\nTablet\n<\/code><\/pre>\n<p>\u0644\u06c1\u0630\u0627\u060c \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u0648 \u0645\u0646\u062f\u0631\u062c\u06c1 \u0630\u06cc\u0644 \u0631\u0627\u0633\u062a\u06d2 \u067e\u0631 \u0639\u0645\u0644 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u0626\u06d2:<\/p>\n<pre><code class=\"language-text\">User\n \u251c\u2500\u2500 Session A\n \u251c\u2500\u2500 Session B\n \u2514\u2500\u2500 Session C\n<\/code><\/pre>\n<p>\u0633\u06cc\u0634\u0646 \u0645\u06cc\u06ba \u0634\u0627\u0645\u0644 \u06c1\u0648 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-ts\">@Schema({ timestamps: true })\nexport class Session {\n  @Prop({ required: true, index: true })\n  userId: Types.ObjectId;\n\n  @Prop({\n    required: true,\n    unique: true,\n    index: true,\n  })\n  sessionId: string;\n\n  @Prop({ required: true })\n  expiresAt: Date;\n\n  @Prop({ default: null })\n  revokedAt: Date | null;\n\n  @Prop()\n  ip?: string;\n\n  @Prop()\n  userAgent?: string;\n\n  @Prop()\n  lastUsedAt?: Date;\n}\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u0633\u06cc\u0634\u0646\u0632 \u06a9\u0648 \u0679\u0631\u06cc\u06a9 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u062c\u06af\u06c1 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0644\u06cc\u06a9\u0646 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u0648 \u0627\u0635\u0644 \u0645\u06cc\u06ba \u062a\u0635\u062f\u06cc\u0642 \u06a9\u06d2 \u0628\u06c1\u0627\u0624 \u0645\u06cc\u06ba \u0627\u0646 \u0631\u06cc\u06a9\u0627\u0631\u0688\u0632 \u06a9\u0627 \u062d\u0648\u0627\u0644\u06c1 \u0627\u0648\u0631 \u0627\u067e \u0688\u06cc\u0679 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u0627\u06af\u0631 \u0627\u06cc\u06a9 \u0645\u062d\u0641\u0648\u0638 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0635\u0631\u0641 JWT \u06a9\u06d2 \u062f\u0633\u062a\u062e\u0637 \u0627\u0648\u0631 \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648\u0646\u06d2 \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0631\u062a\u06cc \u06c1\u06d2\u060c \u062a\u0648 \u0633\u06cc\u0634\u0646 \u06a9\u0648 \u0645\u0646\u0633\u0648\u062e \u06a9\u0631\u0646\u06d2 \u0633\u06d2 \u067e\u06c1\u0644\u06d2 \u0633\u06d2 \u062c\u0627\u0631\u06cc \u06a9\u0631\u062f\u06c1 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u0641\u0648\u0631\u06cc \u0637\u0648\u0631 \u067e\u0631 \u0628\u0627\u0637\u0644 \u0646\u06c1\u06cc\u06ba \u06c1\u0648 \u062c\u0627\u062a\u06d2\u06d4<\/p>\n<p>\u0641\u0648\u0631\u06cc \u0637\u0648\u0631 \u067e\u0631 \u0645\u0646\u0633\u0648\u062e \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2\u060c \u0633\u06cc\u0634\u0646 ID \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u06cc\u06ba (<code>sid<\/code>) \u0645\u0648\u062c\u0648\u062f\u06c1 \u0633\u0631\u0648\u0631 \u0633\u0627\u0626\u06cc\u0688 \u0633\u06cc\u0634\u0646 \u06a9\u06cc \u062d\u0627\u0644\u062a \u067e\u0631 \u0627\u0639\u062a\u0631\u0627\u0636 \u06a9\u0631\u06cc\u06ba\u060c \u06cc\u0627 \u0633\u0633\u0679\u0645 \u06a9\u0648 \u0645\u0646\u0633\u0648\u062e\u06cc \u06a9\u0627 \u062f\u0648\u0633\u0631\u0627 \u0637\u0631\u06cc\u0642\u06c1 \u06a9\u0627\u0631 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u0627\u0633 \u0686\u06cc\u06a9 \u0645\u06cc\u06ba \u06a9\u0627\u0631\u06a9\u0631\u062f\u06af\u06cc \u0627\u0648\u0631 \u062f\u0633\u062a\u06cc\u0627\u0628\u06cc \u06a9\u06d2 \u0627\u062e\u0631\u0627\u062c\u0627\u062a \u06c1\u06cc\u06ba \u062c\u0646 \u067e\u0631 \u0648\u0627\u0636\u062d \u0637\u0648\u0631 \u067e\u0631 \u063a\u0648\u0631 \u06a9\u06cc\u0627 \u062c\u0627\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<h2 id=\"heading-12-refresh-tokens\">12. \u0679\u0648\u06a9\u0646 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0631\u06cc\u06ba\u06d4<\/h2>\n<p>\u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646\u0632 \u0637\u0648\u06cc\u0644 \u0627\u0644\u0645\u062f\u062a \u0627\u0633\u0646\u0627\u062f \u06c1\u06cc\u06ba\u060c \u0627\u0633 \u0644\u06cc\u06d2 \u0627\u0646 \u06a9\u06d2 \u0644\u0627\u0626\u0641 \u0633\u0627\u0626\u06cc\u06a9\u0644 \u06a9\u0648 \u0642\u0644\u06cc\u0644 \u0627\u0644\u0645\u062f\u062a \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u0633\u06d2 \u0632\u06cc\u0627\u062f\u06c1 \u062a\u062d\u0641\u0638 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4 \u0627\u06cc\u06a9 \u0627\u0644\u06af \u0645\u062c\u0645\u0648\u0639\u06c1 \u06af\u0631\u062f\u0634\u06cc \u0633\u0644\u0633\u0644\u06c1 \u0645\u06cc\u06ba \u06c1\u0631 \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u0645\u0646\u0633\u0648\u062e \u06a9\u0631\u0646\u06d2 \u0627\u0648\u0631 \u0622\u0688\u0679 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0633\u06cc\u0634\u0646 \u062f\u0633\u062a\u0627\u0648\u06cc\u0632 \u0645\u06cc\u06ba \u0628\u0631\u0627\u06c1 \u0631\u0627\u0633\u062a \u0627\u06cc\u06a9 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u0630\u062e\u06cc\u0631\u06c1 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2\u060c \u0622\u067e \u0627\u06cc\u06a9 \u0648\u0642\u0641 \u0634\u062f\u06c1 \u0645\u062c\u0645\u0648\u0639\u06c1 \u0628\u0646\u0627 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-ts\">@Schema({ timestamps: true })\nexport class RefreshToken {\n  @Prop({\n    required: true,\n    index: true,\n    type: Types.ObjectId,\n    ref: 'User',\n  })\n  userId: Types.ObjectId;\n\n  @Prop({\n    required: true,\n    index: true,\n  })\n  sessionId: string;\n\n  @Prop({\n    required: true,\n    unique: true,\n    index: true,\n  })\n  tokenHash: string;\n\n  @Prop({\n    required: true,\n    unique: true,\n    index: true,\n  })\n  tokenId: string;\n\n  @Prop({ required: true })\n  expiresAt: Date;\n\n  @Prop({ default: null })\n  revokedAt: Date | null;\n\n  @Prop({ default: null })\n  replacedBy: string | null;\n\n  @Prop()\n  usedAt?: Date;\n\n  @Prop()\n  ip?: string;\n\n  @Prop()\n  userAgent?: string;\n}\n<\/code><\/pre>\n<p>\u0633\u06cc\u0634\u0646 \u0645\u06cc\u06ba \u0627\u06cc\u06a9 \u0679\u0648\u06a9\u0646 \u0630\u062e\u06cc\u0631\u06c1 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646\u0632 \u06a9\u0648 \u0627\u0644\u06af \u06a9\u0644\u06cc\u06a9\u0634\u0646 \u0645\u06cc\u06ba \u06a9\u06cc\u0648\u06ba \u0631\u06a9\u06be\u06cc\u06ba\u061f \u0627\u0633 \u06a9\u06cc \u0648\u062c\u06c1 \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u06a9\u0648\u0626\u06cc \u0628\u06be\u06cc \u06a9\u0627\u0645\u06cc\u0627\u0628 \u0633\u0627\u0626\u06cc\u06a9\u0644 \u0645\u0648\u062c\u0648\u062f\u06c1 \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u062c\u06af\u06c1 \u0644\u06d2 \u0644\u06cc\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u06c1\u0645 \u067e\u0631\u0627\u0646\u06d2 \u0679\u0648\u06a9\u0646 \u06a9\u06d2 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0638\u0627\u06c1\u0631 \u06c1\u0648\u0646\u06d2 \u067e\u0631 \u0627\u0633\u06d2 \u067e\u06c1\u0686\u0627\u0646\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06a9\u0627\u0641\u06cc \u062a\u0627\u0631\u06cc\u062e \u0631\u06a9\u06be\u0646\u0627 \u0686\u0627\u06c1\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u06cc\u06c1 \u062a\u0627\u0631\u06cc\u062e \u0627\u06cc\u06a9 \u0632\u0646\u062c\u06cc\u0631 \u0628\u0646\u0627\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-text\">R1 \u2192 R2 \u2192 R3 \u2192 R4\n<\/code><\/pre>\n<p>\u06c1\u0645 \u0627\u0633 \u062a\u0627\u0631\u06cc\u062e \u06a9\u0627 \u0633\u0631\u0627\u063a \u0644\u06af\u0627\u0646\u06d2 \u06a9\u06d2 \u0642\u0627\u0628\u0644 \u06c1\u0648\u0646\u0627 \u0686\u0627\u06c1\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<h3 id=\"heading-generating-refresh-tokens\">\u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0628\u0646\u0627\u0626\u06cc\u06ba<\/h3>\n<p>\u0622\u067e \u062e\u0641\u06cc\u06c1 \u0637\u0648\u0631 \u067e\u0631 \u0645\u062d\u0641\u0648\u0638 \u0631\u06cc\u0646\u0688\u0645 \u0646\u0645\u0628\u0631 \u062c\u0646\u0631\u06cc\u0679\u0631 \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0628\u0646\u0627 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u062a\u0648\u062b\u06cc\u0642 \u06a9\u06d2 \u0631\u0627\u0632 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0679\u0627\u0626\u0645 \u0627\u0633\u0679\u06cc\u0645\u067e\u060c \u0633\u0627\u062f\u06c1 \u0633\u06cc\u0648\u0688\u0648-\u0631\u06cc\u0646\u0688\u0645 \u0627\u0642\u062f\u0627\u0631\u060c \u06cc\u0627 \u0635\u0627\u0631\u0641 \u06a9\u06d2 \u0632\u06cc\u0631 \u06a9\u0646\u0679\u0631\u0648\u0644 \u062a\u0627\u0631\u0648\u06ba \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u0646\u06c1 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<p>\u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u06a9\u0627 JWT \u06c1\u0648\u0646\u0627 \u0636\u0631\u0648\u0631\u06cc \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u0633\u0631\u0648\u0631 \u067e\u06c1\u0644\u06d2 \u0633\u06d2 \u06c1\u06cc \u0627\u0633\u0679\u06cc\u0679 \u06a9\u0648 \u0627\u0633\u0679\u0648\u0631 \u0627\u0648\u0631 \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0633 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u0628\u06d2 \u062a\u0631\u062a\u06cc\u0628 \u062e\u0641\u06cc\u06c1 \u06a9\u0631\u062f\u06c1 \u0645\u0628\u06c1\u0645 \u062a\u0627\u0631 \u06a9\u0627\u0641\u06cc \u06c1\u06d2\u06d4<\/p>\n<p>\u0627\u0633\u06d2 Node.js \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 \u0628\u0646\u0627\u06cc\u0627 \u062c\u0627 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 <code>crypto<\/code> \u0645\u0627\u0688\u06cc\u0648\u0644\u0632 \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-ts\">import { randomBytes } from 'crypto';\n\nconst refreshToken =\n  randomBytes(32).toString('hex');\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u06c1\u0627\u0626\u06cc \u0627\u06cc\u0646\u0679\u0631\u0648\u067e\u06cc \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0627\u06cc\u06a9 \u0628\u06d2 \u062a\u0631\u062a\u06cc\u0628 \u0631\u0627\u0632 \u067e\u06cc\u062f\u0627 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0631\u06cc\u06a9\u0627\u0631\u0688 \u06a9\u0648 \u0627\u06cc\u06a9 \u0633\u0627\u062a\u06be \u0628\u0627\u0646\u062f\u06be\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06c1\u0645\u06cc\u06ba \u062f\u0648 \u0634\u0646\u0627\u062e\u062a \u06a9\u0646\u0646\u062f\u06af\u0627\u0646 \u06a9\u06cc \u0628\u06be\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2\u06d4 \u0622\u067e \u0627\u0633\u06d2 \u0627\u0633\u06cc \u0637\u0631\u062d \u0628\u0646\u0627 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-ts\">const sessionId =\n  randomBytes(16).toString('hex');\n\nconst tokenId =\n  randomBytes(16).toString('hex');\n<\/code><\/pre>\n<p>\u0627\u0646 \u062f\u0648\u0646\u0648\u06ba \u0627\u0642\u062f\u0627\u0631 \u06a9\u0627 \u062e\u0648\u062f \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0633\u06d2 \u0645\u062e\u062a\u0644\u0641 \u06a9\u0631\u062f\u0627\u0631 \u06c1\u06d2\u06d4<\/p>\n<ul>\n<li><code>sessionId<\/code>    \u0627\u06cc\u06a9 \u0644\u0627\u06af \u0627\u0646 (\u0627\u06cc\u06a9 \u0688\u06cc\u0648\u0627\u0626\u0633 \u06cc\u0627 \u0628\u0631\u0627\u0624\u0632\u0631) \u06a9\u06cc \u0634\u0646\u0627\u062e\u062a \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0633 \u0644\u0627\u06af \u0627\u0646 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0628\u0646\u0627\u0626\u06d2 \u06af\u0626\u06d2 \u062a\u0645\u0627\u0645 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0627\u06cc\u06a9 \u06c1\u06cc \u0645\u0639\u0644\u0648\u0645\u0627\u062a \u06a9\u0648 \u0627\u0633\u0679\u0648\u0631 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 <code>sessionId<\/code>\u06cc\u06c1 \u0633\u0631\u0648\u0631 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06cc\u06c1 \u0645\u0639\u0644\u0648\u0645 \u06a9\u0631\u0646\u06d2 \u06a9\u0627 \u0627\u06cc\u06a9 \u0637\u0631\u06cc\u0642\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u06a9\u0648\u0646 \u0633\u06d2 \u0679\u0648\u06a9\u0646 \u0627\u06cc\u06a9 \u0633\u0627\u062a\u06be \u06c1\u06cc\u06ba \u0627\u0648\u0631 \u0627\u0646 \u0633\u0628 \u06a9\u0648 \u0627\u06cc\u06a9 \u0633\u0627\u062a\u06be \u0645\u0646\u0633\u0648\u062e \u06a9\u0631 \u062f\u06cc\u06ba\u06d4 \u06cc\u06c1 \u0628\u06be\u06cc <code>sid<\/code> \u062f\u0639\u0648\u06cc \u0631\u0633\u0627\u0626\u06cc JWT \u06a9\u06d2 \u0644\u06cc\u06d2 \u06c1\u06d2\u06d4<\/li>\n<li><code>tokenId<\/code>    \u0627\u06cc\u06a9 \u0645\u062e\u0635\u0648\u0635 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u0645\u0646\u0641\u0631\u062f \u0644\u06cc\u0628\u0644\u06d4 \u06af\u06be\u0648\u0645\u0646\u06d2 \u06a9\u06d2 \u062f\u0648\u0631\u0627\u0646 \u067e\u0686\u06be\u0644\u06d2 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u06a9\u0627\u06d4 <code>replacedBy<\/code> \u0645\u06cc\u062f\u0627\u0646 \u0646\u0626\u06d2 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u06a9\u06cc \u0637\u0631\u0641 \u0627\u0634\u0627\u0631\u06c1 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 <code>tokenId<\/code>\u0627\u0633 \u0637\u0631\u062d \u06c1\u0645 \u0632\u0646\u062c\u06cc\u0631 \u0628\u0646\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 <code>R1 \u2192 R2 \u2192 R3<\/code>.<\/li>\n<\/ul>\n<p>\u0646\u06c1 \u06c1\u06cc \u06a9\u0648\u0626\u06cc \u0631\u0627\u0632 \u06c1\u06d2 \u06a9\u06c1 \u0628\u0631\u0627\u0624\u0632\u0631 \u0648\u0627\u067e\u0633 \u0628\u06be\u06cc\u062c\u062a\u0627 \u06c1\u06d2\u06d4 \u0631\u0627\u0632 \u06cc\u06c1 \u06c1\u06d2\u06d4 <code>refreshToken<\/code>. \u06c1\u0645 \u0627\u0628 \u0628\u06be\u06cc \u062a\u0635\u0627\u062f\u0641\u06cc \u0637\u0648\u0631 \u067e\u0631 \u0634\u0646\u0627\u062e\u062a \u06a9\u0646\u0646\u062f\u06af\u0627\u0646 \u062a\u06cc\u0627\u0631 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba \u062a\u0627\u06a9\u06c1 \u0648\u06c1 \u0645\u0646\u0641\u0631\u062f \u0627\u0648\u0631 \u0627\u0646\u062f\u0627\u0632\u06c1 \u0644\u06af\u0627\u0646\u0627 \u0645\u0634\u06a9\u0644 \u06c1\u0648\u06d4<\/p>\n<h3 id=\"heading-hashing-the-refresh-token\">\u0679\u0648\u06a9\u0646 \u06c1\u06cc\u0634\u0646\u06af \u06a9\u0648 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0631\u06cc\u06ba\u06d4<\/h3>\n<p>\u062e\u0627\u0645 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2 \u0627\u06cc\u06a9 \u06c1\u06cc\u0634 \u06a9\u0648 \u0630\u062e\u06cc\u0631\u06c1 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0633\u0641\u0627\u0631\u0634 \u06a9\u06cc \u062c\u0627\u062a\u06cc \u06c1\u06d2 \u062a\u0627\u06a9\u06c1 \u06cc\u06c1 \u06cc\u0642\u06cc\u0646\u06cc \u0628\u0646\u0627\u06cc\u0627 \u062c\u0627 \u0633\u06a9\u06d2 \u06a9\u06c1 \u0627\u06a9\u06cc\u0644\u06d2 \u067e\u0691\u06be\u0627 \u062c\u0627\u0646\u06d2 \u0648\u0627\u0644\u0627 \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u0628\u0631\u0627\u06c1 \u0631\u0627\u0633\u062a \u062f\u0648\u0628\u0627\u0631\u06c1 \u0642\u0627\u0628\u0644 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u0627\u0633\u0646\u0627\u062f \u06a9\u0648 \u0638\u0627\u06c1\u0631 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0686\u0648\u0646\u06a9\u06c1 \u0679\u0648\u06a9\u0646 \u0628\u06d2 \u062a\u0631\u062a\u06cc\u0628 \u06c1\u0648\u062a\u06d2 \u06c1\u06cc\u06ba \u0627\u0648\u0631 \u0627\u0646 \u06a9\u06cc \u0627\u0646\u0679\u0631\u0627\u067e\u06cc \u0632\u06cc\u0627\u062f\u06c1 \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u060c \u0627\u0633 \u0644\u06cc\u06d2 \u062a\u06cc\u0632 \u06a9\u0631\u067e\u0679\u0648\u06af\u0631\u0627\u0641\u06a9 \u06c1\u06cc\u0634 \u062a\u0644\u0627\u0634 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u0648\u0632\u0648\u06ba \u06c1\u06cc\u06ba\u06d4 \u06cc\u06c1 \u0627\u0646\u0633\u0627\u0646\u06cc \u067e\u0627\u0633 \u0648\u0631\u0688\u0632 \u0633\u06d2 \u0645\u062e\u062a\u0644\u0641 \u06c1\u06d2\u060c \u062c\u0633 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0633\u0633\u062a \u067e\u0627\u0633 \u0648\u0631\u0688 \u06c1\u06cc\u0634\u0646\u06af \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<p>\u0628\u0631\u0627\u0624\u0632\u0631 \u06a9\u0648 \u062e\u0627\u0645 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2 \u062a\u0627\u06a9\u06c1 \u0627\u0633\u06d2 \u0628\u0639\u062f \u0645\u06cc\u06ba \u062f\u0648\u0628\u0627\u0631\u06c1 \u0628\u06be\u06cc\u062c\u0627 \u062c\u0627 \u0633\u06a9\u06d2\u060c \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u0627\u06cc\u0633\u0627 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u062a\u0627\u06d4 \u0627\u06af\u0631 \u06a9\u0648\u0626\u06cc \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u06a9\u0648 \u067e\u0691\u06be\u062a\u0627 \u06c1\u06d2\u060c \u062a\u0648 \u0630\u062e\u06cc\u0631\u06c1 \u0634\u062f\u06c1 \u06c1\u06cc\u0634 \u0628\u0631\u0627\u06c1 \u0631\u0627\u0633\u062a \u062f\u0648\u0628\u0627\u0631\u06c1 \u0642\u0627\u0628\u0644 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u0679\u0648\u06a9\u0646 \u0633\u06d2 \u0628\u06c1\u062a \u06a9\u0645 \u0645\u0641\u06cc\u062f \u06c1\u06d2\u06d4 \u06cc\u06c1\u0627\u06ba \u06c1\u0645 \u0627\u0633\u06d2 \u0630\u062e\u06cc\u0631\u06c1 \u06a9\u0631\u0646\u06d2 \u0633\u06d2 \u067e\u06c1\u0644\u06d2 \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u06c1\u06cc\u0634 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-ts\">import { createHash } from 'crypto';\n\nexport function hashToken(\n  token: string,\n): string {\n  return createHash('sha256')\n    .update(token)\n    .digest('hex');\n}\n<\/code><\/pre>\n<p>\u0628\u06c1\u0627\u0624 \u0645\u0646\u062f\u0631\u062c\u06c1 \u0630\u06cc\u0644 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-text\">Raw Refresh Token\n       \u2193\n    SHA-256\n       \u2193\n   MongoDB\n<\/code><\/pre>\n<p>bcrypt \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2 SHA-256 \u06a9\u06cc\u0648\u06ba \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u06cc\u06ba\u061f<\/p>\n<p>\u0627\u0633 \u06a9\u06cc \u0648\u062c\u06c1 \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646\u0632\u060c \u0627\u0646\u0633\u0627\u0646\u06cc \u067e\u0627\u0633 \u0648\u0631\u0688\u0632 \u06a9\u06d2 \u0628\u0631\u0639\u06a9\u0633\u060c \u0628\u06d2 \u062a\u0631\u062a\u06cc\u0628 \u06c1\u0648\u062a\u06d2 \u06c1\u06cc\u06ba \u0627\u0648\u0631 \u0627\u0646 \u06a9\u06cc \u0627\u0646\u0679\u0631\u0627\u067e\u06cc \u0632\u06cc\u0627\u062f\u06c1 \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4 \u0641\u0627\u0633\u0679 \u06a9\u0631\u067e\u0679\u0648\u06af\u0631\u0627\u0641\u06a9 \u06c1\u06cc\u0634 \u0627\u0633 \u0642\u0633\u0645 \u06a9\u06d2 \u0633\u0631\u0648\u0631 \u0633\u0627\u0626\u06cc\u0688 \u062a\u0644\u0627\u0634 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u0648\u0632\u0648\u06ba \u06c1\u06cc\u06ba\u06d4<\/p>\n<h2 id=\"heading-13-access-jwt\">13. JWT \u062a\u06a9 \u0631\u0633\u0627\u0626\u06cc \u062d\u0627\u0635\u0644 \u06a9\u0631\u06cc\u06ba\u06d4<\/h2>\n<p>JWTs \u0628\u0637\u0648\u0631 \u0688\u06cc\u0641\u0627\u0644\u0679 \u062f\u0633\u062a\u062e\u0637 \u0634\u062f\u06c1 \u06c1\u06cc\u06ba\u060c \u0627\u0646\u06a9\u0631\u067e\u0679\u0688 \u0646\u06c1\u06cc\u06ba \u06c1\u06cc\u06ba\u06d4 \u062f\u0633\u062a\u062e\u0637 API \u06a9\u0648 \u062a\u0628\u062f\u06cc\u0644\u06cc\u0648\u06ba \u06a9\u0627 \u067e\u062a\u06c1 \u0644\u06af\u0627\u0646\u06d2 \u0645\u06cc\u06ba \u0645\u062f\u062f \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0644\u06cc\u06a9\u0646 \u062c\u0648 \u0628\u06be\u06cc \u0679\u0648\u06a9\u0646 \u062d\u0627\u0635\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u0648\u06c1 \u0639\u0627\u0645 \u0637\u0648\u0631 \u067e\u0631 \u067e\u06d2 \u0644\u0648\u0688 \u06a9\u0648 \u0688\u06cc \u06a9\u0648\u0688 \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0633 \u0648\u062c\u06c1 \u0633\u06d2\u060c \u067e\u06d2 \u0644\u0648\u0688 \u06a9\u0648 \u0686\u06be\u0648\u0679\u0627 \u0631\u06a9\u06be\u0646\u0627 \u0627\u0648\u0631 \u0635\u0631\u0641 \u0648\u06c1\u06cc \u062f\u0639\u0648\u06d2 \u0634\u0627\u0645\u0644 \u06a9\u0631\u0646\u0627 \u0628\u06c1\u062a\u0631 \u06c1\u06d2 \u062c\u0648 \u0622\u067e \u06a9\u06d2 API \u06a9\u0648 \u062f\u0631\u06a9\u0627\u0631 \u06c1\u06cc\u06ba\u06d4 \u06a9\u0628\u06be\u06cc \u0628\u06be\u06cc \u067e\u0627\u0633 \u0648\u0631\u0688\u060c \u0631\u0627\u0632 \u06cc\u0627 \u063a\u06cc\u0631 \u0636\u0631\u0648\u0631\u06cc \u0630\u0627\u062a\u06cc \u0645\u0639\u0644\u0648\u0645\u0627\u062a \u062f\u0631\u062c \u0646\u06c1 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<p>\u0627\u0633 \u0688\u06cc\u0632\u0627\u0626\u0646 \u06a9\u06d2 \u0644\u06cc\u06d2\u060c \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u06a9\u06d2 \u0644\u06cc\u06d2 \u062a\u06cc\u0646 \u062f\u0639\u0648\u06d2 \u062f\u0631\u06a9\u0627\u0631 \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-ts\">{\n  sub: userId,\n  sid: sessionId,\n  type: 'access'\n}\n<\/code><\/pre>\n<ul>\n<li><code>sub<\/code>    \u06cc\u06c1 \u0645\u0648\u0636\u0648\u0639 \u0633\u06d2 \u0645\u0631\u0627\u062f \u06c1\u06d2 \u0627\u0648\u0631 \u0639\u0627\u0645 \u0637\u0648\u0631 \u067e\u0631 \u0635\u0627\u0631\u0641 \u06a9\u06cc \u0634\u0646\u0627\u062e\u062a \u06a9\u0627 \u062d\u0648\u0627\u0644\u06c1 \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4<\/li>\n<li><code>sid<\/code>    \u0627\u0633 \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 \u0633\u06cc\u0634\u0646 \u0622\u0626\u06cc \u0688\u06cc\u06d4<\/li>\n<li><code>type<\/code>    \u062d\u0627\u062f\u062b\u0627\u062a\u06cc \u0637\u0648\u0631 \u067e\u0631 \u0627\u06cc\u06a9 \u0645\u062e\u062a\u0644\u0641 \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u0642\u0633\u0645 \u06a9\u0648 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u06a9\u06d2 \u0628\u0637\u0648\u0631 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u0646\u06d2 \u0633\u06d2 \u0631\u0648\u06a9\u062a\u0627 \u06c1\u06d2\u06d4<\/li>\n<\/ul>\n<h3 id=\"heading-creating-the-access-token\">\u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u0628\u0646\u0627\u0626\u06cc\u06ba<\/h3>\n<p>\u06cc\u06c1 \u0633\u0628 \u0633\u06d2 \u0628\u06c1\u062a\u0631 \u06c1\u06d2 \u06a9\u06c1 \u062f\u0633\u062a\u062e\u0637 \u06a9\u0648 \u0645\u0627\u062e\u0630 \u06a9\u06d2 \u06a9\u0646\u0679\u0631\u0648\u0644 \u0633\u06d2 \u0628\u0627\u06c1\u0631 \u0631\u06a9\u06be\u06cc\u06ba \u0627\u0648\u0631 \u0622\u063a\u0627\u0632 \u06a9\u06d2 \u062f\u0648\u0631\u0627\u0646 \u0627\u0633 \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u06a9\u0631\u06cc\u06ba\u06d4 \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u06a9\u06cc \u062d\u06a9\u0645\u062a \u0639\u0645\u0644\u06cc\u0648\u06ba \u06a9\u0648 \u06c1\u0645 \u0622\u06c1\u0646\u06af \u0627\u0644\u06af\u0648\u0631\u062a\u06be\u0645 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2 \u0627\u0648\u0631 \u062a\u0648\u0642\u0639\u0627\u062a \u06a9\u0627 \u062f\u0639\u0648\u06cc \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u0627\u0644\u06af\u0648\u0631\u062a\u06be\u0645 \u06a9\u0648 \u0635\u0631\u0641 \u0627\u0633 \u0644\u06cc\u06d2 \u0642\u0628\u0648\u0644 \u0646\u06c1 \u06a9\u0631\u06cc\u06ba \u06a9\u06c1 \u06cc\u06c1 \u0622\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u0679\u0648\u06a9\u0646 \u0645\u06cc\u06ba \u0638\u0627\u06c1\u0631 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-ts\">async createAccessToken(data: {\n  userId: string;\n  sessionId: string;\n}) {\n  return this.jwtService.signAsync(\n    {\n      sub: data.userId,\n      sid: data.sessionId,\n      type: 'access',\n    },\n    {\n      secret:\n        this.configService.getOrThrow<string>(\n          'JWT_ACCESS_SECRET',\n        ),\n      expiresIn: this.configService.getOrThrow<string>(\n        'ACCESS_TOKEN_EXPIRES_IN',\n      ),\n    },\n  );\n}\n<\/string><\/string><\/code><\/pre>\n<p>\u0645\u062e\u062a\u0635\u0631 \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648\u0646\u06d2 \u06a9\u06cc \u0645\u062f\u062a \u062c\u0627\u0646 \u0628\u0648\u062c\u06be \u06a9\u0631 \u06c1\u06d2\u06d4 \u062a\u0634\u06a9\u06cc\u0644 \u0634\u062f\u06c1 \u0644\u0627\u0626\u0641 \u0679\u0627\u0626\u0645 \u0633\u0627\u0626\u0646\u0646\u06af \u06a9\u0648\u0688 \u0645\u06cc\u06ba \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06c1\u0648\u0646\u06d2 \u0648\u0627\u0644\u06cc \u0627\u0642\u062f\u0627\u0631 \u0633\u06d2 \u0645\u0645\u0627\u062b\u0644 \u06c1\u0648\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u060c \u0627\u0648\u0631 JWT \u062d\u06a9\u0645\u062a \u0639\u0645\u0644\u06cc \u06a9\u0648 \u0645\u062a\u0648\u0642\u0639 \u0627\u0644\u06af\u0648\u0631\u062a\u06be\u0645\u060c \u062f\u0633\u062a\u062e\u0637\u060c \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648\u0646\u06d2 \u0627\u0648\u0631 \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u0642\u0633\u0645 \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u06a9\u0631\u0646\u06cc \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u0627\u06af\u0631 API \u0633\u06cc\u0634\u0646 \u0645\u0646\u0633\u0648\u062e\u06cc \u06a9\u06cc \u0628\u06be\u06cc \u062c\u0627\u0646\u0686 \u06a9\u0631\u062a\u0627 \u06c1\u06d2: <code>sid<\/code> \u0641\u0639\u0627\u0644 \u0633\u06cc\u0634\u0646 \u0631\u06cc\u06a9\u0627\u0631\u0688\u0632 \u06a9\u0627 \u062f\u0639\u0648\u06cc \u06a9\u0631\u0646\u0627\u06d4<\/p>\n<p>\u0627\u06af\u0631 \u0622\u067e \u06a9\u0627 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u0686\u0648\u0631\u06cc \u06c1\u0648 \u06af\u06cc\u0627 \u06c1\u06d2\u060c \u062a\u0648 \u06cc\u0642\u06cc\u0646\u06cc \u0628\u0646\u0627\u0626\u06cc\u06ba \u06a9\u06c1 \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u0639\u0645\u0631 \u0645\u062d\u062f\u0648\u062f \u06c1\u06d2\u06d4 \u0627\u06cc\u06a9 \u0686\u06be\u0648\u0679\u0627 \u0679\u06cc \u0679\u06cc \u0627\u06cc\u0644 \u0646\u0642\u0635\u0627\u0646 \u06a9\u06cc \u06a9\u06be\u0691\u06a9\u06cc \u06a9\u0648 \u06a9\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<h2 id=\"heading-14-login\">14. \u0644\u0627\u06af \u0627\u0646<\/h2>\n<p>\u0627\u0628 \u062c\u0628 \u06a9\u06c1 \u06c1\u0645\u0627\u0631\u06d2 \u067e\u0627\u0633 \u0635\u0627\u0631\u0641\u060c \u0633\u06cc\u0634\u0646\u060c \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646\u060c \u0627\u0648\u0631 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u06c1\u06cc\u06ba\u060c \u06c1\u0645 \u0627\u0646\u06c1\u06cc\u06ba \u0627\u067e\u0646\u06d2 \u0644\u0627\u06af \u0627\u0646 \u0627\u06cc\u0646\u0688 \u067e\u0648\u0627\u0626\u0646\u0679 \u0645\u06cc\u06ba \u0627\u06cc\u06a9 \u0633\u0627\u062a\u06be \u0631\u06a9\u06be \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0627\u0633 \u0633\u06cc\u06a9\u0634\u0646 \u0645\u06cc\u06ba\u060c \u06c1\u0645 \u0633\u0628 \u0633\u06d2 \u067e\u06c1\u0644\u06d2 \u0645\u062c\u0645\u0648\u0639\u06cc \u0628\u06c1\u0627\u0624\u060c \u067e\u06be\u0631 \u0639\u0645\u0644 \u062f\u0631\u0622\u0645\u062f\u060c \u0627\u0648\u0631 \u067e\u06be\u0631 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u06a9\u0648 HttpOnly \u06a9\u0648\u06a9\u06cc \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u06a9\u06cc\u0648\u06ba \u067e\u0627\u0633 \u06a9\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2 \u06a9\u0648 \u062f\u06cc\u06a9\u06be\u06cc\u06ba \u06af\u06d2\u06d4<\/p>\n<h3 id=\"heading-the-login-flow\">\u0644\u0627\u06af \u0627\u0646 \u06a9\u0627 \u0628\u06c1\u0627\u0624<\/h3>\n<p>\u06cc\u06c1 \u062a\u0635\u0648\u0631 \u06a9\u0631\u0646\u06d2 \u0645\u06cc\u06ba \u0622\u067e \u06a9\u06cc \u0645\u062f\u062f \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u0645\u06a9\u0645\u0644 \u062a\u0635\u0648\u0631 \u06a9\u0627 \u0628\u06c1\u0627\u0624 \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u06cc\u06c1 \u0633\u0628 \u06a9\u06cc\u0633\u06d2 \u06a9\u0627\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-text\">POST \/auth\/login\n       \u2502\n       \u25bc\nFind user\n       \u2502\n       \u25bc\nCompare password\n       \u2502\n       \u25bc\nCreate Session\n       \u2502\n       \u251c\u2500\u2500 sessionId\n       \u2502\n       \u25bc\nCreate Refresh Token\n       \u2502\n       \u251c\u2500\u2500 random secret\n       \u251c\u2500\u2500 hash\n       \u2514\u2500\u2500 store hash\n       \u2502\n       \u25bc\nCreate Access JWT\n       \u2502\n       \u25bc\nSet HttpOnly Cookie\n       \u2502\n       \u25bc\nReturn accessToken\n<\/code><\/pre>\n<h3 id=\"heading-login-implementation\">\u0644\u0627\u06af \u0627\u0646 \u0639\u0645\u0644 \u062f\u0631\u0622\u0645\u062f<\/h3>\n<p>\u06cc\u06c1 \u0645\u062b\u0627\u0644 \u0627\u06c1\u0645 \u0627\u0642\u062f\u0627\u0645\u0627\u062a \u06a9\u0648 \u0638\u0627\u06c1\u0631 \u06a9\u0631\u062a\u06cc \u06c1\u06d2\u060c \u0644\u06cc\u06a9\u0646 \u0645\u06a9\u0645\u0644 \u0646\u0641\u0627\u0630 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0636\u0631\u0648\u0631\u06cc \u06c1\u06d2 \u06a9\u06c1 DTOs \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u06a9\u0631\u06cc\u06ba\u060c \u0634\u0631\u062d \u06a9\u0648 \u0645\u062d\u062f\u0648\u062f \u06a9\u0631\u0646\u0627\u060c \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u06a9\u06cc \u063a\u0644\u0637\u06cc\u0648\u06ba \u06a9\u0648 \u06c1\u06cc\u0646\u0688\u0644 \u06a9\u0631\u06cc\u06ba\u060c \u0627\u0648\u0631 \u0627\u0633 \u0628\u0627\u062a \u06a9\u0648 \u06cc\u0642\u06cc\u0646\u06cc \u0628\u0646\u0627\u0626\u06cc\u06ba \u06a9\u06c1 \u0633\u06cc\u0634\u0646 \u0627\u0648\u0631 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0631\u06cc\u06a9\u0627\u0631\u0688\u0632 \u0645\u0633\u062a\u0642\u0644 \u0637\u0648\u0631 \u067e\u0631 \u0628\u0646\u0627\u0626\u06d2 \u062c\u0627\u0626\u06cc\u06ba\u06d4 \u0628\u0631\u0627\u06c1 \u06a9\u0631\u0645 \u0638\u0627\u06c1\u0631 \u0646\u06c1 \u06a9\u0631\u06cc\u06ba \u06a9\u06c1 \u0622\u06cc\u0627 \u0622\u067e \u06a9\u0627 \u0627\u06cc \u0645\u06cc\u0644 \u067e\u062a\u06c1 \u06cc\u0627 \u067e\u0627\u0633 \u0648\u0631\u0688 \u063a\u0644\u0637 \u06c1\u06d2\u06d4 \u0627\u0633 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2\u060c \u0627\u06cc\u06a9 \u0639\u0627\u0645 \u0633\u0646\u062f\u06cc \u063a\u0644\u0637\u06cc \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-ts\">async login(\n  dto: LoginDto,\n  req: Request,\n  res: Response,\n) {\n  const email =\n    dto.email.trim().toLowerCase();\n\n  const user =\n    await this.usersService.findByEmail(email);\n\n  if (!user) {\n    throw new UnauthorizedException(\n      'Invalid credentials',\n    );\n  }\n\n  const valid =\n    await bcrypt.compare(\n      dto.password,\n      user.passwordHash,\n    );\n\n  if (!valid) {\n    throw new UnauthorizedException(\n      'Invalid credentials',\n    );\n  }\n\n  const sessionId =\n    randomBytes(16).toString('hex');\n\n  const refreshToken =\n    randomBytes(32).toString('hex');\n\n  const tokenId =\n    randomBytes(16).toString('hex');\n\n  const refreshTokenHash =\n    hashToken(refreshToken);\n\n  const expiresAt =\n    new Date(\n      Date.now() +\n      7 * 24 * 60 * 60 * 1000,\n    );\n\n  await this.sessionsService.createSession({\n    userId: user._id.toString(),\n    sessionId,\n    expiresAt,\n    ip: req.ip,\n    userAgent:\n      req.headers['user-agent'],\n  });\n\n  await this.sessionsService.createRefreshToken({\n    userId: user._id.toString(),\n    sessionId,\n    tokenHash: refreshTokenHash,\n    tokenId,\n    expiresAt,\n    ip: req.ip,\n    userAgent:\n      req.headers['user-agent'],\n  });\n\n  const accessToken =\n    await this.tokenService.createAccessToken({\n      userId: user._id.toString(),\n      sessionId,\n    });\n\n  res.cookie(\n    'refresh_token',\n    refreshToken,\n    {\n      httpOnly: true,\n      secure:\n        this.configService.get(\n          'NODE_ENV',\n        ) === 'production',\n      sameSite: 'strict',\n      path: '\/auth',\n      maxAge:\n        7 * 24 * 60 * 60 * 1000,\n    },\n  );\n\n  return {\n    accessToken,\n  };\n}\n<\/code><\/pre>\n<p>\u0622\u0626\u06cc\u06d2 \u0627\u0633 \u06a9\u0648\u0688 \u06a9\u06cc \u0627\u06c1\u0645 \u062e\u0635\u0648\u0635\u06cc\u0627\u062a \u06a9\u0648 \u062f\u06cc\u06a9\u06be\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<ul>\n<li>\u0633\u0628 \u0633\u06d2 \u067e\u06c1\u0644\u06d2\u060c \u0627\u06cc \u0645\u06cc\u0644 \u06a9\u0648 \u0645\u0639\u0645\u0648\u0644 \u0628\u0646\u0627\u0626\u06cc\u06ba\u06d4 \u0627\u06cc \u0645\u06cc\u0644\u0632 \u06a9\u0627\u0679 \u06a9\u0631 \u0686\u06be\u0648\u0679\u06d2 \u062d\u0631\u0648\u0641 \u0645\u06cc\u06ba \u062f\u06a9\u06be\u0627\u0626\u06d2 \u062c\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 <code>User@Example.com<\/code> \u0627\u0648\u0631 <code>user@example.com<\/code> \u0627\u0633\u06cc \u0627\u06a9\u0627\u0624\u0646\u0679 \u06a9\u0648 \u062a\u0644\u0627\u0634 \u06a9\u0631\u06cc\u06ba\u06d4<\/li>\n<li>\u0627\u0633 \u06a9\u06d2 \u0646\u062a\u06cc\u062c\u06d2 \u0645\u06cc\u06ba \u0627\u06cc\u06a9 \u0639\u0627\u0645 \u0633\u0646\u062f \u06a9\u06cc \u062e\u0631\u0627\u0628\u06cc \u06c1\u0648\u06af\u06cc\u06d4 \u062f\u0648 \u062c\u06af\u06c1\u06cc\u06ba \u062c\u06c1\u0627\u06ba \u0644\u0627\u06af \u0627\u0646 \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648 \u0633\u06a9\u062a\u0627 \u06c1\u06d2 \u0627\u06af\u0631 \u0627\u06cc \u0645\u06cc\u0644 \u0635\u0627\u0631\u0641 \u0633\u06d2 \u0645\u0645\u0627\u062b\u0644 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2 \u06cc\u0627 \u0627\u06af\u0631 \u067e\u0627\u0633 \u0648\u0631\u0688 \u0630\u062e\u06cc\u0631\u06c1 \u0634\u062f\u06c1 \u06c1\u06cc\u0634 \u0633\u06d2 \u0645\u06cc\u0644 \u0646\u06c1\u06cc\u06ba \u06a9\u06be\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u062f\u0648\u0646\u0648\u06ba \u0635\u0648\u0631\u062a\u0648\u06ba \u0645\u06cc\u06ba \u06a9\u0648\u0688 \u0627\u06cc\u06a9 \u062c\u06cc\u0633\u0627 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4 <code>UnauthorizedException('Invalid credentials')<\/code>NestJS \u0627\u0633\u06d2 \u06a9\u0644\u0627\u0626\u0646\u0679 \u06a9\u0648 \u0648\u0627\u067e\u0633 \u06a9\u0631\u062a\u0627 \u06c1\u06d2: <code>401 Unauthorized<\/code> \u0627\u0633 \u067e\u06cc\u063a\u0627\u0645 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u062c\u0648\u0627\u0628 \u062f\u06cc\u06ba\u06d4<\/li>\n<li>\u0627\u06af\u0644\u0627\u060c \u0627\u067e\u0646\u0627 \u067e\u0627\u0633 \u0648\u0631\u0688 \u0686\u06cc\u06a9 \u06a9\u0631\u06cc\u06ba\u06d4 <code>bcrypt.compare()<\/code>. \u062c\u0645\u0639 \u06a9\u0631\u0627\u0626\u06d2 \u06af\u0626\u06d2 \u067e\u0627\u0633 \u0648\u0631\u0688\u0632 \u06a9\u0648 \u0645\u062d\u0641\u0648\u0638 \u06a9\u0631\u062f\u06c1 \u067e\u0627\u0633 \u0648\u0631\u0688\u0632 \u06a9\u06d2 \u062e\u0644\u0627\u0641 \u0686\u06cc\u06a9 \u06a9\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 <code>passwordHash<\/code>\u0633\u0627\u062f\u06c1 \u0645\u062a\u0646 \u06a9\u06d2 \u067e\u0627\u0633 \u0648\u0631\u0688\u0632 \u06a9\u06d2 \u0645\u062e\u0627\u0644\u0641 \u0646\u06c1 \u06c1\u0648\u06ba\u06d4<\/li>\n<li>\u067e\u06be\u0631 \u0627\u06cc\u06a9 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u0628\u0646\u0627\u0626\u06cc\u06ba\u06d4 \u0627\u06af\u0631 \u06a9\u0627\u0645\u06cc\u0627\u0628 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u060c \u062a\u0648 \u06a9\u0648\u0688 \u0627\u06cc\u06a9 \u0628\u06d2 \u062a\u0631\u062a\u06cc\u0628 \u0634\u0646\u0627\u062e\u062a \u06a9\u0646\u0646\u062f\u06c1 \u0627\u0648\u0631 \u0627\u06cc\u06a9 \u0628\u06d2 \u062a\u0631\u062a\u06cc\u0628 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u062a\u06cc\u0627\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u06a9\u0648 SHA-256 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u06c1\u06cc\u0634 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0648\u0631 MongoDB \u0645\u06cc\u06ba \u0633\u06cc\u0634\u0646 \u0627\u0648\u0631 \u0679\u0648\u06a9\u0646 \u0631\u06cc\u06a9\u0627\u0631\u0688\u0632 (\u0635\u0631\u0641 \u06c1\u06cc\u0634\u060c \u062e\u0627\u0645 \u0679\u0648\u06a9\u0646 \u0646\u06c1\u06cc\u06ba) \u06a9\u0648 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u062f\u0648\u0646\u0648\u06ba \u06a9\u06cc \u0645\u06cc\u0639\u0627\u062f 7 \u062f\u0646\u0648\u06ba \u0645\u06cc\u06ba \u062e\u062a\u0645 \u06c1\u0648 \u062c\u0627\u062a\u06cc \u06c1\u06d2\u06d4<\/li>\n<li>\u0627\u0633 \u06a9\u06d2 \u0628\u0639\u062f\u060c \u06c1\u0645 \u0635\u0631\u0641 \u0648\u06c1\u06cc \u0648\u0627\u067e\u0633 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba \u062c\u0648 \u06af\u0627\u06c1\u06a9 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4 \u0631\u0633\u067e\u0627\u0646\u0633 \u0628\u0627\u0688\u06cc \u0645\u06cc\u06ba \u0635\u0631\u0641 \u0645\u062e\u062a\u0635\u0631 \u0645\u062f\u062a \u06a9\u06d2 \u062c\u0648\u0627\u0628\u0627\u062a \u06c1\u0648\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 <code>accessToken<\/code>. \u062e\u0627\u0645 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u06a9\u0648\u06a9\u06cc \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u0628\u0631\u0627\u0624\u0632\u0631 \u067e\u0631 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u060c JSON \u0628\u0627\u0688\u06cc \u06a9\u06d2 \u0646\u06c1\u06cc\u06ba\u06d4<\/li>\n<li>\u0622\u062e\u0631 \u0645\u06cc\u06ba\u060c \u06a9\u0648\u06a9\u06cc \u06a9\u06cc \u062a\u0631\u062a\u06cc\u0628\u0627\u062a \u0645\u0648\u062c\u0648\u062f \u06c1\u06cc\u06ba. <code>httpOnly<\/code> \u062c\u0627\u0648\u0627 \u0627\u0633\u06a9\u0631\u067e\u0679 \u0633\u06d2 \u06a9\u0648\u06a9\u06cc\u0632 \u0686\u06be\u067e\u0627\u0626\u06cc\u06ba\u06d4 <code>secure<\/code> (\u067e\u0631\u0648\u0688\u06a9\u0634\u0646 \u0645\u06cc\u06ba) \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 \u06a9\u06c1 \u06cc\u06c1 \u0635\u0631\u0641 HTTPS \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u0688\u06cc\u0644\u06cc\u0648\u0631 \u06a9\u06cc\u0627 \u062c\u0627\u0626\u06d2 \u06af\u0627\u06d4 <code>sameSite: 'strict'<\/code> \u0628\u0631\u0627\u0624\u0632\u0631 \u06a9\u06d2 \u0645\u0646\u0633\u0644\u06a9 \u06c1\u0648\u0646\u06d2 \u067e\u0631 \u067e\u0627\u0628\u0646\u062f\u06cc\u0627\u06ba \u0644\u06af\u0627\u0626\u06cc\u06ba\u060c <code>path: '\/auth'<\/code> \u0627\u0633 \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 \u06a9\u06c1 \u0628\u0631\u0627\u0624\u0632\u0631 \u0635\u0631\u0641 \u0628\u06be\u06cc\u062c\u062a\u0627 \u06c1\u06d2: <code>\/auth<\/code> \u0627\u06cc\u0646\u0688 \u067e\u0648\u0627\u0626\u0646\u0679\u0633\u060c \u062a\u0645\u0627\u0645 API \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u0646\u06c1\u06cc\u06ba\u06d4<\/li>\n<\/ul>\n<p>\u062a\u0648 \u0622\u067e \u06a9\u0648 \u06cc\u06c1 \u06a9\u06cc\u0648\u06ba \u0638\u0627\u06c1\u0631 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2 \u06a9\u06c1 \u0622\u067e \u06a9\u0627 \u0627\u06cc \u0645\u06cc\u0644 \u0627\u06cc\u0688\u0631\u06cc\u0633 \u06cc\u0627 \u067e\u0627\u0633 \u0648\u0631\u0688 \u063a\u0644\u0637 \u06c1\u06d2\u061f \u062a\u0635\u0648\u0631 \u06a9\u0631\u06cc\u06ba \u06a9\u06c1 API \u0627\u06cc\u06a9 \u06a9\u06cc\u0633 \u06a9\u06d2 \u0644\u06cc\u06d2 &quot;\u0627\u0633 \u0627\u06cc \u0645\u06cc\u0644 \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u0627 \u06a9\u0648\u0626\u06cc \u0627\u06a9\u0627\u0624\u0646\u0679 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2&#8221; \u0627\u0648\u0631 \u062f\u0648\u0633\u0631\u06d2 \u06a9\u06cc\u0633 \u06a9\u06d2 \u0644\u06cc\u06d2 &quot;\u063a\u0644\u0637 \u067e\u0627\u0633 \u0648\u0631\u0688&#8221; \u06a9\u0627 \u062c\u0648\u0627\u0628 \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0633 \u06a9\u06d2 \u0628\u0639\u062f \u062d\u0645\u0644\u06c1 \u0622\u0648\u0631 \u0627\u06cc \u0645\u06cc\u0644 \u067e\u062a\u0648\u06ba \u06a9\u06cc \u0627\u06cc\u06a9 \u0644\u0645\u0628\u06cc \u0641\u06c1\u0631\u0633\u062a \u062c\u0645\u0639 \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u06cc\u06c1 \u0645\u0639\u0644\u0648\u0645 \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u0633\u0633\u0679\u0645 \u067e\u0631 \u06a9\u0646 \u067e\u062a\u0648\u06ba \u06a9\u06d2 \u0627\u06a9\u0627\u0624\u0646\u0679\u0633 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u0627\u0633\u06d2 \u06a9\u06c1\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2 <em>\u0635\u0627\u0631\u0641 \u06a9\u06cc \u06af\u0646\u062a\u06cc<\/em>\u06be\u062f\u0641 \u0634\u062f\u06c1 \u067e\u0627\u0633 \u0648\u0631\u0688 \u06a9\u0627 \u0627\u0646\u062f\u0627\u0632\u06c1 \u0644\u06af\u0627\u0646\u06d2\u060c \u0627\u0633\u0646\u0627\u062f \u0628\u06be\u0631\u0646\u06d2\u060c \u0627\u0648\u0631 \u0641\u0634\u0646\u06af \u0645\u06cc\u06ba \u0645\u062f\u062f \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u06cc\u06a9 \u0627\u0648\u0631 \u0627\u06cc\u06a9 \u06c1\u06cc <code>Invalid credentials<\/code> \u06cc\u06c1\u0627\u06ba \u062a\u06a9 \u06a9\u06c1 \u0627\u06af\u0631 \u0622\u067e \u062c\u0648\u0627\u0628 \u062f\u06cc\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u062d\u0645\u0644\u06c1 \u0622\u0648\u0631 \u06a9\u0648 \u06a9\u0648\u0626\u06cc \u0627\u0634\u0627\u0631\u06c1 \u0646\u06c1\u06cc\u06ba \u06c1\u0648\u06af\u0627 \u06a9\u06c1 \u0622\u067e \u06a9\u06cc \u0627\u0633\u0646\u0627\u062f \u06a9\u0627 \u06a9\u0648\u0646 \u0633\u0627 \u062d\u0635\u06c1 \u063a\u0644\u0637 \u06c1\u06d2\u06d4<\/p>\n<p>\u0646\u0648\u0679 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u0636\u0627\u0641\u06cc \u062a\u0641\u0635\u06cc\u0644\u0627\u062a: \u0627\u0633 \u0645\u062b\u0627\u0644 \u0645\u06cc\u06ba\u060c \u0627\u06af\u0631 \u0635\u0627\u0631\u0641 \u0645\u0648\u062c\u0648\u062f \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u060c \u062a\u0648 \u06a9\u0648\u0688 \u0646\u06c1\u06cc\u06ba \u0686\u0644\u06d2 \u06af\u0627 \u0627\u0648\u0631 \u0641\u0648\u0631\u0627\u064b \u0648\u0627\u067e\u0633 \u0622\u062c\u0627\u0626\u06d2 \u06af\u0627\u06d4 <code>bcrypt.compare()<\/code>\u0644\u06c1\u0630\u0627\u060c \u062c\u0648\u0627\u0628 \u063a\u0644\u0637 \u067e\u0627\u0633 \u0648\u0631\u0688 \u06a9\u06d2 \u062c\u0648\u0627\u0628 \u0633\u06d2 \u06a9\u06c1\u06cc\u06ba \u0632\u06cc\u0627\u062f\u06c1 \u062a\u06cc\u0632 \u06c1\u0648 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0633 \u0645\u0639\u0627\u0645\u0644\u06d2 \u0645\u06cc\u06ba \u0633\u062e\u062a \u0639\u0645\u0644 \u062f\u0631\u0622\u0645\u062f \u06a9\u0627 \u0645\u0648\u0627\u0632\u0646\u06c1 \u0688\u0645\u06cc \u06c1\u06cc\u0634 \u0633\u06d2 \u06a9\u06cc\u0627 \u062c\u0627 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u060c \u0644\u06c1\u0630\u0627 \u062f\u0648\u0646\u0648\u06ba \u0631\u0627\u0633\u062a\u06d2 \u0627\u06cc\u06a9 \u062c\u06cc\u0633\u06d2 \u0648\u0642\u062a \u0644\u06cc\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u0648\u0631 \u0627\u0633\u06d2 \u0634\u0631\u062d \u06a9\u06cc \u062d\u062f \u06a9\u06d2 \u0633\u0627\u062a\u06be \u062c\u0648\u0691\u06cc\u06ba \u062c\u0633\u06d2 \u06c1\u0645 \u0628\u0639\u062f \u0645\u06cc\u06ba \u0634\u0627\u0645\u0644 \u06a9\u0631\u06cc\u06ba \u06af\u06d2\u06d4<\/p>\n<h3 id=\"heading-why-httponly\">\u0635\u0631\u0641 Http \u06a9\u06cc\u0648\u06ba\u061f<\/h3>\n<p><code>HttpOnly<\/code>    \u06cc\u06c1 \u0648\u06c1 \u062e\u0635\u0648\u0635\u06cc\u0627\u062a \u06c1\u06cc\u06ba \u062c\u0648 \u06a9\u0648\u06a9\u06cc\u0632 \u067e\u0631 \u0633\u06cc\u0679 \u06a9\u06cc \u062c\u0627 \u0633\u06a9\u062a\u06cc \u06c1\u06cc\u06ba\u06d4 \u06cc\u06c1 \u0628\u0631\u0627\u0624\u0632\u0631 \u06a9\u0648 \u06a9\u06c1\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 &quot;\u0627\u0633 \u06a9\u0648\u06a9\u06cc \u06a9\u0648 \u0635\u0631\u0641 HTTP \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u06d2 \u0644\u06cc\u06d2 \u0631\u06a9\u06be\u06cc\u06ba \u0627\u0648\u0631 \u0635\u0641\u062d\u06c1 JavaScript \u06a9\u0648 \u0627\u0633\u06d2 \u067e\u0691\u06be\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u0646\u06c1 \u062f\u06cc\u06ba\u06d4&#8221; \u062c\u0628 \u0633\u0631\u0648\u0631 \u06a9\u0648\u06a9\u06cc \u0628\u06be\u06cc\u062c\u062a\u0627 \u06c1\u06d2\u060c \u062a\u0648 \u06cc\u06c1 \u067e\u0631\u0627\u067e\u0631\u0679\u06cc\u0632 \u0633\u06cc\u0679 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0628\u0631\u0627\u0624\u0632\u0631 \u0627\u0646 \u06a9\u0648 \u0646\u0627\u0641\u0630 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0644\u0627\u06af \u0627\u0646 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0628\u0639\u062f\u060c \u0633\u0631\u0648\u0631 \u06a9\u0627 \u062c\u0648\u0627\u0628 \u062d\u0633\u0628 \u0630\u06cc\u0644 \u06c1\u06d2 (\u0645\u062b\u0627\u0644 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0645\u062e\u062a\u0635\u0631 \u06a9\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2):<\/p>\n<pre><code class=\"language-http\">Set-Cookie: refresh_token=9f2c...e81a; HttpOnly; Secure; SameSite=Strict; Path=\/auth; Max-Age=604800\n<\/code><\/pre>\n<p>\u062c\u0628 \u0635\u0641\u062d\u06c1 \u067e\u0631 \u06a9\u0648\u0626\u06cc \u0627\u0633\u06a9\u0631\u067e\u0679 \u0645\u0639\u06cc\u0627\u0631\u06cc \u0628\u0631\u0627\u0624\u0632\u0631 API \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u06a9\u0648\u06a9\u06cc \u06a9\u0648 \u067e\u0691\u06be\u0646\u06d2 \u06a9\u06cc \u06a9\u0648\u0634\u0634 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c <code>refresh_token<\/code> \u06a9\u0648\u0626\u06cc \u06a9\u0648\u06a9\u06cc\u0632 \u0646\u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-js\">console.log(document.cookie);\n\/\/ \"\" \u2190 refresh_token isn't included, because it's HttpOnly\n<\/code><\/pre>\n<p>\u0645\u0646\u062f\u0631\u062c\u06c1 \u0628\u0627\u0644\u0627 \u06a9\u0648\u0688 \u0628\u0644\u0627\u06a9 \u062f\u0648 \u0686\u06cc\u0632\u06cc\u06ba \u062f\u06a9\u06be\u0627\u062a\u0627 \u06c1\u06d2: <code>HttpOnly<\/code> \u0633\u0631\u0648\u0631 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06c1 \u0628\u06be\u06cc\u062c\u06cc \u06af\u0626\u06cc \u06a9\u0648\u06a9\u06cc\u0632 \u06a9\u06d2 \u062c\u06be\u0646\u0688\u06d2 \u0627\u0648\u0631 \u06a9\u0648\u06a9\u06cc \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u0631\u062a\u06d2 \u0648\u0642\u062a \u062c\u0627\u0648\u0627 \u0627\u0633\u06a9\u0631\u067e\u0679 \u06a9\u06cc\u0627 \u062f\u06cc\u06a9\u06be\u062a\u0627 \u06c1\u06d2\u06d4 JavaScript \u0642\u062f\u0631 \u0646\u06c1\u06cc\u06ba \u067e\u0691\u06be \u0633\u06a9\u062a\u0627 \u06a9\u06cc\u0648\u0646\u06a9\u06c1 \u0628\u0631\u0627\u0624\u0632\u0631 \u062c\u0627\u0646 \u0628\u0648\u062c\u06be \u06a9\u0631 HttpOnly \u06a9\u0648\u06a9\u06cc\u0632 \u06a9\u0648 \u062e\u0627\u0631\u062c \u06a9\u0631 \u062f\u06cc\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 <code>document.cookie<\/code>. \u06a9\u0648\u06a9\u06cc\u0632 \u06a9\u0648 \u0628\u0631\u0627\u0624\u0632\u0631 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u06c1\u06cc \u0630\u062e\u06cc\u0631\u06c1 \u0627\u0648\u0631 \u0645\u0646\u0638\u0645 \u06a9\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u060c \u0646\u06c1 \u06a9\u06c1 \u0635\u0641\u062d\u06c1 \u067e\u0631 \u062c\u0627\u0648\u0627 \u0627\u0633\u06a9\u0631\u067e\u0679 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2\u060c \u0627\u0648\u0631 \u0628\u0631\u0627\u0624\u0632\u0631 \u0635\u0631\u0641 \u0627\u0633 \u0648\u0642\u062a \u06a9\u0648\u06a9\u06cc\u0632 \u067e\u0691\u06be\u062a\u0627 \u06c1\u06d2 \u062c\u0628 \u0627\u0633\u06d2 \u0628\u0627\u06c1\u0631 \u062c\u0627\u0646\u06d2 \u0648\u0627\u0644\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0645\u0646\u0633\u0644\u06a9 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<p>\u062a\u0627\u06c1\u0645\u060c \u0628\u0631\u0627\u0624\u0632\u0631 \u062e\u0648\u062f \u0628\u062e\u0648\u062f \u06a9\u0648\u06a9\u06cc\u0632 \u06a9\u0648 \u0645\u0645\u0627\u062b\u0644 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u0633\u06d2 \u0645\u0646\u0633\u0644\u06a9 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u062c\u06cc\u0633\u06d2: <code>POST \/auth\/refresh<\/code>. \u06cc\u06c1\u06cc \u0648\u062c\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u06a9\u0648\u06a9\u06cc \u067e\u0631 \u0645\u0628\u0646\u06cc \u0627\u062e\u062a\u062a\u0627\u0645\u06cc \u0646\u06a9\u0627\u062a \u06a9\u0648 CSRF \u0633\u06d2 \u0622\u06af\u0627\u06c1 \u0688\u06cc\u0632\u0627\u0626\u0646 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4 \u06c1\u0645 \u0628\u0639\u062f \u0645\u06cc\u06ba \u0627\u0633 \u06a9\u0627 \u0627\u062d\u0627\u0637\u06c1 \u06a9\u0631\u06cc\u06ba \u06af\u06d2\u06d4<\/p>\n<p>\u062a\u0648 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u06a9\u0627 \u0631\u0627\u0633\u062a\u06c1 \u06cc\u06c1 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-text\">Server sets cookie (HttpOnly)\n          \u2193\nBrowser stores it\n          \u2193\nPage JavaScript asks for cookies \u2192 refresh_token is not visible\n          \u2193\nBrowser itself attaches it to matching requests (for example POST \/auth\/refresh)\n<\/code><\/pre>\n<p>\u06cc\u06c1\u0627\u06ba \u06cc\u06c1 \u0628\u06c1\u062a\u0631\u06cc\u0646 \u0637\u0631\u06cc\u0642\u06c1 \u06a9\u06cc\u0648\u06ba \u06c1\u06d2\u060c \u0627\u0648\u0631 \u0622\u067e \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u0686\u0648\u0631\u06cc \u06a9\u0648 \u06a9\u06cc\u0633\u06d2 \u0631\u0648\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u061f \u06a9\u0633\u06cc \u0648\u06cc\u0628 \u0635\u0641\u062d\u06c1 \u0633\u06d2 \u0679\u0648\u06a9\u0646 \u0686\u0648\u0631\u06cc \u06a9\u0631\u0646\u06d2 \u06a9\u0627 \u0633\u0628 \u0633\u06d2 \u0639\u0627\u0645 \u0637\u0631\u06cc\u0642\u06c1 \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u0627\u0633 \u0635\u0641\u062d\u06c1 \u067e\u0631 \u0628\u062f\u0646\u06cc\u062a\u06cc \u067e\u0631 \u0645\u0628\u0646\u06cc JavaScript (XSS) \u06a9\u0648 \u0686\u0644\u0627\u0646\u0627\u060c \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u067e\u0691\u06be\u0646\u0627\u060c \u0627\u0648\u0631 \u067e\u06be\u0631 \u0627\u0633\u06d2 \u062d\u0645\u0644\u06c1 \u0622\u0648\u0631 \u06a9\u06d2 \u0632\u06cc\u0631 \u06a9\u0646\u0679\u0631\u0648\u0644 \u0633\u0631\u0648\u0631 \u067e\u0631 \u0628\u06be\u06cc\u062c\u0646\u0627 \u06c1\u06d2\u06d4 \u0627\u06af\u0631 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 HttpOnly \u06a9\u0648\u06a9\u06cc \u0645\u06cc\u06ba \u06c1\u06d2\u060c \u062a\u0648 \u0627\u0633 \u0627\u0633\u06a9\u0631\u067e\u0679 \u0645\u06cc\u06ba \u067e\u0691\u06be\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06a9\u0686\u06be \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u060c \u0627\u0633 \u0644\u06cc\u06d2 \u0637\u0648\u06cc\u0644 \u0645\u062f\u062a\u06cc \u0627\u0633\u0646\u0627\u062f \u06a9\u0648 \u06a9\u0627\u067e\u06cc \u0646\u06c1\u06cc\u06ba \u06a9\u06cc\u0627 \u062c\u0627 \u0633\u06a9\u062a\u0627 \u0627\u0648\u0631 \u0628\u0639\u062f \u0645\u06cc\u06ba \u062d\u0645\u0644\u06c1 \u0622\u0648\u0631 \u06a9\u06d2 \u0627\u067e\u0646\u06d2 \u06a9\u0645\u067e\u06cc\u0648\u0679\u0631 \u067e\u0631 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u0646\u06c1\u06cc\u06ba \u06a9\u06cc\u0627 \u062c\u0627 \u0633\u06a9\u062a\u0627\u06d4 \u06cc\u06c1 \u06a9\u0644\u0627\u0626\u0646\u0679 \u0633\u0627\u0626\u0688 JavaScript \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u0679\u0648\u06a9\u0646 \u0686\u0648\u0631\u06cc \u06a9\u06d2 \u062e\u0644\u0627\u0641 \u0627\u06cc\u06a9 \u0627\u06c1\u0645 \u062f\u0641\u0627\u0639 \u06c1\u06d2\u06d4 \u06cc\u06c1 \u0645\u06a9\u0645\u0644 \u062f\u0641\u0627\u0639 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u0635\u0641\u062d\u06c1 \u06a9\u06d2 \u06a9\u06be\u0644\u06d2 \u06c1\u0648\u0646\u06d2 \u06a9\u06d2 \u0628\u0627\u0648\u062c\u0648\u062f \u0628\u06be\u06cc \u06a9\u0633\u06cc \u0635\u0641\u062d\u06c1 \u067e\u0631 \u0686\u0644\u0646\u06d2 \u0648\u0627\u0644\u06cc \u0628\u062f\u0646\u06cc\u062a\u06cc \u067e\u0631 \u0645\u0628\u0646\u06cc \u0627\u0633\u06a9\u0631\u067e\u0679 \u0622\u067e \u0633\u06d2 \u0628\u0637\u0648\u0631 \u0635\u0627\u0631\u0641 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u06a9\u0631 \u0633\u06a9\u062a\u06cc \u06c1\u06cc\u06ba\u060c \u0627\u0633 \u0644\u06cc\u06d2 \u0627\u0633 \u0679\u06cc\u0648\u0679\u0648\u0631\u06cc\u0644 \u06a9\u06d2 \u0644\u06cc\u06d2 \u062f\u06cc\u06af\u0631 \u062d\u0641\u0627\u0638\u062a\u06cc \u0627\u0642\u062f\u0627\u0645\u0627\u062a \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2\u06d4<\/p>\n<h2 id=\"heading-15-angular-authservice\">15. \u06a9\u0648\u0646\u06cc\u06cc \u062a\u0635\u062f\u06cc\u0642 \u06a9\u06cc \u062e\u062f\u0645\u062a<\/h2>\n<p>\u06a9\u06c1 <code>AuthService<\/code> \u0622\u067e \u06a9\u06cc \u0627\u0646\u06af\u0648\u0644\u0631 \u0627\u06cc\u067e \u0645\u06cc\u06ba \u0627\u06cc\u06a9 \u0648\u0627\u062d\u062f \u0645\u0642\u0627\u0645 \u062c\u0648 \u062a\u0635\u062f\u06cc\u0642 \u06a9\u06d2 \u0627\u062e\u062a\u062a\u0627\u0645\u06cc \u0646\u0642\u0637\u06c1 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0628\u0627\u062a \u0686\u06cc\u062a \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u0631\u06a9\u06be\u062a\u0627 \u06c1\u06d2\u06d4 \u062c\u0632\u0648 \u06a9\u0628\u06be\u06cc \u06a9\u0627\u0644 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u062a\u0627 <code>\/auth\/login<\/code> \u06cc\u0627 \u0679\u0648\u06a9\u0646 \u062e\u0648\u062f \u0630\u062e\u06cc\u0631\u06c1 \u06a9\u0631\u06cc\u06ba\u06d4 \u0648\u06c1 \u062e\u062f\u0645\u062a \u0645\u0627\u0646\u06af\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u06c1\u0645\u0627\u0631\u0627 \u06cc\u06c1\u06cc \u0645\u0637\u0644\u0628 \u06c1\u06d2 \u062c\u0628 \u06c1\u0645 \u06a9\u06c1\u062a\u06d2 \u06c1\u06cc\u06ba \u06a9\u06c1 \u0633\u0631\u0648\u0633 \u062a\u0648\u062b\u06cc\u0642 \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u0648 \u0645\u0631\u06a9\u0632\u06cc \u0628\u0646\u0627\u062a\u06cc \u06c1\u06d2 \u0627\u0648\u0631 \u0645\u06cc\u0645\u0648\u0631\u06cc \u0645\u06cc\u06ba \u0679\u0648\u06a9\u0646 \u0627\u0642\u062f\u0627\u0631 \u062a\u06a9 \u0631\u0633\u0627\u0626\u06cc \u062d\u0627\u0635\u0644 \u06a9\u0631\u062a\u06cc \u06c1\u06d2\u06d4 \u0644\u0627\u06af \u0627\u0646\u060c \u0631\u06cc\u0641\u0631\u06cc\u0634\u060c \u0627\u0648\u0631 \u0644\u0627\u06af \u0622\u0624\u0679 \u06a9\u06d2 \u0644\u06cc\u06d2 HTTP \u06a9\u0627\u0644\u0632 \u0633\u0628\u06be\u06cc \u0627\u06cc\u06a9 \u06a9\u0644\u0627\u0633 \u0645\u06cc\u06ba \u06c1\u06cc\u06ba\u060c \u0627\u0648\u0631 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u0627\u0633 \u06a9\u06d2 \u0627\u0646\u062f\u0631 \u0627\u06cc\u06a9 \u0646\u062c\u06cc \u0641\u06cc\u0644\u0688 \u0645\u06cc\u06ba \u06c1\u06d2\u06d4 \u06a9\u06cc\u0648\u0646\u06a9\u06c1 \u0679\u0648\u06a9\u0646 \u0628\u0627\u0642\u0627\u0639\u062f\u06c1 \u06a9\u0644\u0627\u0633 \u06a9\u06cc \u062e\u0635\u0648\u0635\u06cc\u0627\u062a \u06c1\u06cc\u06ba ( <code>localStorage<\/code>)\u060c \u0648\u06c1 \u0635\u0641\u062d\u06c1 \u06a9\u0648 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0644\u0648\u0688 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0628\u0639\u062f \u063a\u0627\u0626\u0628 \u06c1\u0648 \u062c\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u0648\u0631 \u0627\u06cc\u067e \u06a9\u06d2 \u062a\u0645\u0627\u0645 \u062d\u0635\u0648\u06ba \u06a9\u0648 \u0633\u0686\u0627\u0626\u06cc \u06a9\u06d2 \u0627\u06cc\u06a9 \u0630\u0631\u06cc\u0639\u06c1 \u0633\u06d2 \u0627\u06cc\u06a9 \u062c\u06cc\u0633\u06cc \u0645\u0648\u062c\u0648\u062f\u06c1 \u0627\u0642\u062f\u0627\u0631 \u0645\u0644\u062a\u06cc \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u06a9\u06c1 <code>withCredentials: true<\/code> \u06c1\u0631 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0645\u06cc\u06ba \u0627\u062e\u062a\u06cc\u0627\u0631\u0627\u062a \u0622\u067e \u06a9\u06d2 \u0628\u0631\u0627\u0624\u0632\u0631 \u06a9\u0648 \u06a9\u0648\u06a9\u06cc\u0632 \u06a9\u0648 \u0634\u0627\u0645\u0644 \u06a9\u0631\u0646\u06d2 \u0627\u0648\u0631 \u0642\u0628\u0648\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u06c1\u062f\u0627\u06cc\u062a \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 <code>Set-Cookie<\/code> \u06a9\u0631\u0627\u0633 \u0627\u0648\u0631\u06cc\u062c\u0646 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u06d2 \u06c1\u06cc\u0688\u0631\u06d4 \u0627\u0633 \u06a9\u06d2 \u0628\u063a\u06cc\u0631\u060c \u06a9\u0648\u06a9\u06cc\u0632 \u06a9\u0648 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0646\u06c1\u06cc\u06ba \u06a9\u06cc\u0627 \u062c\u0627\u0626\u06d2 \u06af\u0627 \u0627\u0648\u0631 \u0646\u06c1 \u06c1\u06cc \u0628\u06be\u06cc\u062c\u06cc \u062c\u0627\u0626\u06d2 \u06af\u06cc \u062c\u0628 Angular \u0627\u0648\u0631 API \u06a9\u0648 \u0645\u062e\u062a\u0644\u0641 \u0627\u0635\u0644\u06cc\u062a \u0633\u06d2 \u0686\u0644\u0627\u06cc\u0627 \u062c\u0627\u0626\u06d2 \u06af\u0627\u06d4<\/p>\n<p>\u0627\u06cc\u06a9 \u062d\u0642\u06cc\u0642\u06cc \u0627\u06cc\u067e \u0645\u06cc\u06ba\u060c \u0627\u06af\u0631 \u0622\u067e \u062f\u0648\u0628\u0627\u0631\u06c1 \u0644\u0648\u0688 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0628\u0639\u062f \u0627\u06cc\u06a9 \u062f\u0631\u0633\u062a \u0633\u06cc\u0634\u0646 \u06a9\u0648 \u0628\u062d\u0627\u0644 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u062a\u06d2 \u06c1\u06cc\u06ba \u062a\u0648 \u0622\u067e \u0627\u06cc\u067e\u0644\u06cc \u06a9\u06cc\u0634\u0646 \u06a9\u06cc \u062d\u0627\u0644\u062a \u06a9\u06d2 \u062c\u0648\u0627\u0628 \u06a9\u0648 \u062c\u0648\u0691\u0646\u0627\u060c \u063a\u0644\u0637\u06cc\u0648\u06ba \u06a9\u0648 \u06c1\u06cc\u0646\u0688\u0644 \u06a9\u0631\u0646\u0627\u060c \u0627\u0648\u0631 \u0627\u06cc\u067e\u0644\u06cc\u06a9\u06cc\u0634\u0646 \u0627\u0633\u0679\u0627\u0631\u0679 \u0627\u067e \u067e\u0631 \u0627\u0646\u06c1\u06cc\u06ba \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06ba \u06af\u06d2\u06d4<\/p>\n<pre><code class=\"language-ts\">@Injectable({\n  providedIn: 'root',\n})\nexport class AuthService {\n  private accessToken: string | null = null;\n\n  private readonly apiUrl=\"http:\/\/localhost:3000\/auth\";\n\n  constructor(\n    private readonly http: HttpClient,\n  ) {}\n\n  login(credentials: LoginRequest) {\n    return this.http.post<loginresponse>(\n      `${this.apiUrl}\/login`,\n      credentials,\n      {\n        withCredentials: true,\n      },\n    );\n  }\n\n  refresh() {\n    return this.http.post<loginresponse>(\n      `${this.apiUrl}\/refresh`,\n      {},\n      {\n        withCredentials: true,\n      },\n    );\n  }\n\n  logout() {\n    return this.http.post(\n      `${this.apiUrl}\/logout`,\n      {},\n      {\n        withCredentials: true,\n      },\n    );\n  }\n\n  setAccessToken(token: string) {\n    this.accessToken = token;\n  }\n\n  getAccessToken() {\n    return this.accessToken;\n  }\n\n  clearAccessToken() {\n    this.accessToken = null;\n  }\n}\n<\/loginresponse><\/loginresponse><\/code><\/pre>\n<p>\u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646\u0632 \u06a9\u0648 \u0628\u0627\u0642\u0627\u0639\u062f\u06c1 \u0627\u0646\u06af\u0648\u0644\u0631 \u0645\u06cc\u0645\u0648\u0631\u06cc \u0645\u06cc\u06ba \u0631\u06a9\u06be\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u067e\u0648\u0631\u06d2 \u0635\u0641\u062d\u06c1 \u06a9\u0648 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0644\u0648\u0688 \u06a9\u0631\u0646\u06d2 \u067e\u0631 \u0636\u0627\u0626\u0639 \u06c1\u0648 \u062c\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0686\u0648\u0646\u06a9\u06c1 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0627\u06cc\u06a9 HttpOnly \u06a9\u0648\u06a9\u06cc \u0645\u06cc\u06ba \u06c1\u06d2\u060c Angular \u0627\u0633\u06d2 \u0628\u0631\u0627\u06c1 \u0631\u0627\u0633\u062a \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u0628\u062d\u0627\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0646\u06c1\u06cc\u06ba \u067e\u0691\u06be \u0633\u06a9\u062a\u0627\u06d4 \u0622\u067e \u06a9\u06cc \u0627\u06cc\u067e \u06a9\u0648 \u0627\u0633\u0679\u0627\u0631\u0679 \u0627\u067e \u067e\u0631 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0627\u06cc\u0646\u0688 \u067e\u0648\u0627\u0626\u0646\u0679 \u06a9\u0648 \u06a9\u0627\u0644 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2 \u0627\u0648\u0631 \u0635\u0627\u0631\u0641 \u06a9\u0648 \u0644\u0627\u06af \u0622\u0624\u0679 \u062d\u0627\u0644\u062a \u0645\u06cc\u06ba \u0648\u0627\u067e\u0633 \u06a9\u0631 \u06a9\u06d2 \u0646\u0627\u06a9\u0627\u0645\u06cc \u06a9\u0648 \u06c1\u06cc\u0646\u0688\u0644 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<p>\u0622\u067e \u06a9\u0648 CSRF \u06a9\u06d2 \u062e\u0644\u0627\u0641 \u0627\u0633 \u0627\u062e\u062a\u062a\u0627\u0645\u06cc \u0646\u0642\u0637\u06c1 \u06a9\u06cc \u062d\u0641\u0627\u0638\u062a \u06a9\u0631\u0646\u06cc \u0686\u0627\u06c1\u06cc\u06d2 \u0627\u0648\u0631 \u0627\u0633\u06d2 \u0635\u0631\u0641 \u0645\u0637\u0644\u0648\u0628\u06c1 \u0641\u0631\u0646\u0679 \u0627\u06cc\u0646\u0688 \u0633\u0648\u0631\u0633 \u0633\u06d2 \u06c1\u06cc \u0627\u0633\u0646\u0627\u062f \u0642\u0628\u0648\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u062a\u0631\u062a\u06cc\u0628 \u062f\u06cc\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<p>\u0627\u06c1\u0645 \u0641\u0646 \u062a\u0639\u0645\u06cc\u0631 \u0645\u06cc\u06ba \u0634\u0627\u0645\u0644 \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-text\">Access Token\n    \u2193\nAngular memory\n\nRefresh Token\n    \u2193\nBrowser HttpOnly Cookie\n<\/code><\/pre>\n<h3 id=\"heading-angular-interceptor\">\u0632\u0627\u0648\u06cc\u06c1 \u0627\u0646\u0679\u0631\u0633\u06cc\u067e\u0679\u0631<\/h3>\n<p>\u0627\u06cc\u06a9 \u0627\u0646\u0679\u0631\u0633\u06cc\u067e\u0679\u0631 \u06a9\u0648\u0688 \u06a9\u0627 \u0627\u06cc\u06a9 \u0679\u06a9\u0691\u0627 \u06c1\u06d2 \u062c\u0648 \u0622\u067e \u06a9\u06cc \u0627\u0646\u06af\u0648\u0644\u0631 \u0627\u06cc\u067e \u0627\u0648\u0631 \u0646\u06cc\u0679 \u0648\u0631\u06a9 \u06a9\u06d2 \u062f\u0631\u0645\u06cc\u0627\u0646 \u0628\u06cc\u0679\u06be\u062a\u0627 \u06c1\u06d2\u06d4 \u062a\u0645\u0627\u0645 HTTP \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u06c1\u06cc\u06ba\u06d4 <code>HttpClient<\/code> \u0622\u067e \u0628\u0627\u06c1\u0631 \u062c\u0627\u062a\u06d2 \u06c1\u0648\u0626\u06d2 \u0627\u0633 \u0633\u06d2 \u06af\u0632\u0631\u062a\u06d2 \u06c1\u06cc\u06ba (\u0627\u0648\u0631 \u0648\u0627\u067e\u0633\u06cc \u067e\u0631 \u06a9\u0648\u0626\u06cc \u0631\u062f\u0639\u0645\u0644) \u062a\u0627\u06a9\u06c1 \u0622\u067e \u0627\u0633 \u06a9\u0627 \u0645\u0639\u0627\u0626\u0646\u06c1 \u06a9\u0631 \u0633\u06a9\u06cc\u06ba \u06cc\u0627 \u0627\u0633\u06d2 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631 \u0633\u06a9\u06cc\u06ba\u06d4 \u06cc\u06c1 \u0627\u06cc\u06a9 \u062c\u06af\u06c1 \u067e\u0631 \u06a9\u0631\u0627\u0633 \u0627\u06cc\u0688\u0679 HTTP \u0631\u0648\u06cc\u06d2 \u06a9\u0648 \u0644\u0627\u06af\u0648 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u0641\u06cc\u062f \u06c1\u06d2\u06d4<\/p>\n<p>&quot;\u06a9\u0631\u0627\u0633 \u06a9\u0679\u0646\u06af&#8221; \u0633\u06d2 \u0645\u0631\u0627\u062f \u0627\u06cc\u0633\u06cc \u06a9\u0627\u0631\u0631\u0648\u0627\u0626\u06cc\u0627\u06ba \u06c1\u06cc\u06ba \u062c\u0648 \u0628\u06c1\u062a \u0633\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u067e\u0631 \u0644\u0627\u06af\u0648 \u06c1\u0648\u062a\u06cc \u06c1\u06cc\u06ba\u060c \u0642\u0637\u0639 \u0646\u0638\u0631 \u0627\u0633 \u06a9\u06d2 \u06a9\u06c1 \u0627\u0633 \u0641\u0646\u06a9\u0634\u0646 \u0646\u06d2 \u0627\u0646\u06c1\u06cc\u06ba \u0628\u0646\u0627\u06cc\u0627 \u06c1\u06d2\u060c \u062c\u06cc\u0633\u06d2 \u06a9\u06c1 \u062a\u0648\u062b\u06cc\u0642\u06cc \u06c1\u06cc\u0688\u0631 \u0634\u0627\u0645\u0644 \u06a9\u0631\u0646\u0627\u060c \u0644\u0627\u06af\u0646\u06af \u06a9\u0631\u0646\u0627\u060c \u06cc\u0627 \u063a\u0644\u0637\u06cc \u0633\u06d2 \u06c1\u06cc\u0646\u0688\u0644 \u06a9\u0631\u0646\u0627\u06d4 \u0627\u0646\u0679\u0631\u0633\u06cc\u067e\u0679\u0631 \u06a9\u06d2 \u0628\u063a\u06cc\u0631\u060c \u0622\u067e \u06a9\u0648 \u06c1\u0631 \u0627\u0633 \u0633\u0631\u0648\u0633 \u0645\u06cc\u06ba \u0627\u0633 \u0645\u0646\u0637\u0642 \u06a9\u0648 \u062f\u06c1\u0631\u0627\u0646\u0627 \u067e\u0691\u06d2 \u06af\u0627 \u062c\u0648 \u0622\u067e \u06a9\u06d2 API \u06a9\u0648 \u06a9\u0627\u0644 \u06a9\u0631\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<p>\u0622\u067e \u06a9\u0648 \u0627\u067e\u0646\u06d2 API \u062a\u06a9 \u062f\u0627\u0626\u0631\u06c1 \u06a9\u0627\u0631 \u06a9\u0648 \u062a\u0646\u06af \u0631\u06a9\u06be\u0646\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2\u060c \u0627\u0648\u0631 \u0627\u0633 \u0628\u0627\u062a \u06a9\u0648 \u06cc\u0642\u06cc\u0646\u06cc \u0628\u0646\u0627\u0626\u06cc\u06ba \u06a9\u06c1 \u0622\u067e \u063a\u06cc\u0631 \u0645\u062a\u0648\u0642\u0639 \u0637\u0648\u0631 \u067e\u0631 \u0645\u0648\u062c\u0648\u062f\u06c1 \u062a\u0648\u062b\u06cc\u0642\u06cc \u06c1\u06cc\u0688\u0631 \u06a9\u0648 \u0627\u0648\u0648\u0631 \u0631\u0627\u0626\u0679 \u0646\u06c1\u06cc\u06ba \u06a9\u0631 \u0631\u06c1\u06d2 \u06c1\u06cc\u06ba \u06cc\u0627 \u0627\u0633\u0646\u0627\u062f \u06a9\u0648 \u063a\u06cc\u0631 \u0645\u062a\u0639\u0644\u0642\u06c1 \u0630\u0631\u0627\u0626\u0639 \u0633\u06d2 \u0645\u0646\u0633\u0644\u06a9 \u0646\u06c1\u06cc\u06ba \u06a9\u0631 \u0631\u06c1\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u062a\u0645\u0627\u0645 \u0645\u062d\u0641\u0648\u0638 \u0634\u062f\u06c1 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u0648 \u0627\u06cc\u06a9 \u062f\u0633\u062a\u06cc\u0627\u0628 \u06c1\u0648\u0646\u06d2 \u067e\u0631 \u062e\u0648\u062f \u0628\u062e\u0648\u062f \u0627\u06cc\u06a9 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u0645\u0644 \u062c\u0627\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u0645\u062f\u0627\u062e\u0644\u062a \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u0648\u06ba \u06a9\u0648 \u063a\u06cc\u0631 \u0645\u062a\u0639\u0644\u0642\u06c1 \u0641\u0631\u06cc\u0642 \u062b\u0627\u0644\u062b URLs \u0633\u06d2 \u0645\u0646\u0633\u0644\u06a9 \u06c1\u0648\u0646\u06d2 \u0633\u06d2 \u06af\u0631\u06cc\u0632 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2 \u0627\u0648\u0631 \u0628\u0627\u0631 \u0628\u0627\u0631 \u0644\u0627\u06af \u0627\u0646 \u06a9\u0631\u0646\u06d2 \u06cc\u0627 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0627\u06cc\u0646\u0688 \u067e\u0648\u0627\u0626\u0646\u0679 \u067e\u0631 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u06a9\u0648\u0634\u0634 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u0646\u06cc \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<p>\u062a\u0645\u0627\u0645 \u0645\u062d\u0641\u0648\u0638 \u0634\u062f\u06c1 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u0648 \u062e\u0648\u062f \u0628\u062e\u0648\u062f \u0645\u0648\u0635\u0648\u0644 \u06c1\u0648\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2:<\/p>\n<pre><code class=\"language-http\">Authorization: Bearer <accesstoken>\n<\/accesstoken><\/code><\/pre>\n<pre><code class=\"language-ts\">export const authInterceptor:\n  HttpInterceptorFn = (req, next) => {\n\n  const authService =\n    inject(AuthService);\n\n  const token =\n    authService.getAccessToken();\n\n  const authReq = token\n    ? req.clone({\n        setHeaders: {\n          Authorization:\n            `Bearer ${token}`,\n        },\n      })\n    : req;\n\n  return next(authReq);\n};\n<\/code><\/pre>\n<h2 id=\"heading-16-handling-expired-access-tokens\">16. \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u06c1\u06cc\u0646\u0688\u0644 \u06a9\u0631\u0646\u0627<\/h2>\n<p>\u0686\u0648\u0646\u06a9\u06c1 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u062c\u0627\u0646 \u0628\u0648\u062c\u06be \u06a9\u0631 \u0642\u0644\u06cc\u0644 \u0627\u0644\u0645\u062f\u062a \u06c1\u0648\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u0633 \u0644\u06cc\u06d2 \u06c1\u0631 \u06a9\u0644\u0627\u0626\u0646\u0679 \u06a9\u0648 \u0622\u062e\u0631\u06a9\u0627\u0631 \u0627\u06cc\u06a9 \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u0679\u0648\u06a9\u0646 \u06a9\u0627 \u0633\u0627\u0645\u0646\u0627 \u06a9\u0631\u0646\u0627 \u067e\u0691\u06d2 \u06af\u0627\u06d4 \u0627\u0633 \u0633\u06cc\u06a9\u0634\u0646 \u0645\u06cc\u06ba\u060c \u06c1\u0645 \u062f\u06cc\u06a9\u06be\u06cc\u06ba \u06af\u06d2 \u06a9\u06c1 \u0622\u067e \u06a9\u06cc \u0627\u06cc\u067e \u0627\u06cc\u0633\u06d2 \u06a9\u06cc\u0633\u0632 \u06a9\u0627 \u06a9\u06cc\u0633\u06d2 \u067e\u062a\u06c1 \u0644\u06af\u0627\u062a\u06cc \u06c1\u06d2\u060c \u0627\u06cc\u06a9 \u06c1\u06cc \u0648\u0642\u062a \u0645\u06cc\u06ba \u0645\u062a\u0639\u062f\u062f \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u06d2 \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648\u0646\u06d2 \u067e\u0631 \u06a9\u06cc\u0627 \u063a\u0644\u0637 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u06a9\u0633 \u0637\u0631\u062d Angular \u0627\u0648\u0631 NestJS \u0627\u0633\u06d2 \u062d\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u0644 \u06a9\u0631 \u06a9\u0627\u0645 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u0641\u0631\u0636 \u06a9\u0631\u06cc\u06ba \u06a9\u06c1 \u0622\u067e \u06a9\u06d2 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648 \u06af\u0626\u06cc \u06c1\u06d2\u06d4 \u067e\u0633\u062f\u06cc\u062f \u0648\u0627\u067e\u0633 <code>401 Unauthorized<\/code> \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u063a\u0627\u0626\u0628\u060c \u063a\u0644\u0637\u060c \u06cc\u0627 \u062e\u062a\u0645 \u06c1\u0648 \u06af\u06cc\u0627 \u06c1\u06d2\u06d4 \u06a9\u0648\u0626\u06cc \u0631\u0627\u0633\u062a\u06c1 \u0646\u06c1\u06cc\u06ba <code>401<\/code> \u0627\u0633 \u06a9\u0627 \u06c1\u0645\u06cc\u0634\u06c1 \u06cc\u06c1 \u0645\u0637\u0644\u0628 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2 \u06a9\u06c1 \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648 \u06af\u0626\u06cc \u06c1\u06d2\u060c \u0627\u0633 \u0644\u06cc\u06d2 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u06a9\u0648\u0634\u0634 \u0635\u0631\u0641 \u0645\u062a\u0639\u0644\u0642\u06c1 \u0645\u062d\u0641\u0648\u0638 API \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06d2 \u0644\u06cc\u06d2 \u06a9\u06cc \u062c\u0627\u0646\u06cc \u0686\u0627\u06c1\u06cc\u06d2 \u0627\u0648\u0631 \u0627\u0633\u06d2 \u063a\u06cc\u0631 \u0645\u0639\u06cc\u0646\u06c1 \u0645\u062f\u062a \u062a\u06a9 \u0646\u06c1\u06cc\u06ba \u062f\u06c1\u0631\u0627\u06cc\u0627 \u062c\u0627\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u0627\u06af\u0631 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648\u062c\u0627\u062a\u0627 \u06c1\u06d2 \u062a\u0648\u060c \u0627\u0646 \u0645\u06cc\u0645\u0648\u0631\u06cc \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u0635\u0627\u0641 \u06a9\u0631\u06cc\u06ba\u060c \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634\u06cc\u06ba \u0628\u0646\u062f \u06a9\u0631\u06cc\u06ba\u060c \u0627\u0648\u0631 \u0635\u0627\u0631\u0641 \u06a9\u0648 \u0644\u0627\u06af \u0622\u0624\u0679 \u0641\u0644\u0648 \u067e\u0631 \u0648\u0627\u067e\u0633 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<p><strong>\u0645\u062c\u06be\u06d2 \u06a9\u06cc\u0633\u06d2 \u067e\u062a\u06c1 \u0686\u0644\u06d2 \u06af\u0627 \u06a9\u06c1 \u06a9\u0648\u0646 \u0633\u0627 \u0645\u0639\u0627\u0645\u0644\u06c1 \u06c1\u06d2\u061f<\/strong> \u0628\u0646\u06cc\u0627\u062f\u06cc \u0637\u0648\u0631 \u067e\u0631\u060c \u062a\u06cc\u0646\u0648\u06ba \u0646\u0627\u06a9\u0627\u0645\u06cc\u0627\u06ba \u0627\u06cc\u06a9 \u06c1\u06cc \u0631\u062f\u0639\u0645\u0644 \u067e\u06cc\u062f\u0627 \u06a9\u0631\u062a\u06cc \u06c1\u06cc\u06ba\u06d4 <code>401 Unauthorized<\/code>. \u0644\u06cc\u06a9\u0646 \u0627\u0633 \u06a9\u06d2 \u0646\u06cc\u0686\u06d2\u060c JWT \u0644\u0627\u0626\u0628\u0631\u06cc\u0631\u06cc \u062c\u0627\u0646\u062a\u06cc \u06c1\u06d2 \u06a9\u06c1 \u062a\u0635\u062f\u06cc\u0642 \u06a9\u06cc\u0648\u06ba \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648\u0626\u06cc\u06d4 \u06cc\u06c1 \u0631\u067e\u0648\u0631\u0679 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 <code>TokenExpiredError<\/code> \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u0679\u0648\u06a9\u0646\u0632 \u06a9\u06d2 \u0644\u06cc\u06d2\u060c \u06af\u0645\u0634\u062f\u06c1 \u06c1\u06cc\u0688\u0631 \u06a9\u06d2 \u0646\u062a\u06cc\u062c\u06d2 \u0645\u06cc\u06ba &quot;\u06a9\u0648\u0626\u06cc \u062a\u0648\u062b\u06cc\u0642 \u0646\u06c1\u06cc\u06ba \u0679\u0648\u06a9\u0646&#8221; \u067e\u06cc\u063a\u0627\u0645 \u06c1\u0648\u06af\u0627\u060c \u0627\u0648\u0631 \u0686\u06be\u06cc\u0691 \u0686\u06be\u0627\u0691 \u0679\u0648\u06a9\u0646\u0632 \u06a9\u06d2 \u0644\u06cc\u06d2\u060c \u063a\u0644\u0637 \u062f\u0633\u062a\u062e\u0637 \u062c\u06cc\u0633\u06cc \u063a\u0644\u0637\u06cc\u0627\u06ba \u0631\u0648\u0646\u0645\u0627 \u06c1\u0648\u06ba \u06af\u06cc\u06d4 \u0627\u0633 \u0648\u062c\u06c1 \u06a9\u0648 \u06a9\u0644\u0627\u0626\u0646\u0679 \u062a\u06a9 \u067e\u06c1\u0646\u0686\u0627\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0622\u067e \u0627\u0633\u06d2 \u0627\u0648\u0648\u0631 \u0631\u0627\u0626\u0688 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 <code>handleRequest<\/code> \u062c\u06d2 \u0688\u0628\u0644\u06cc\u0648 \u0679\u06cc \u06af\u0627\u0631\u0688 \u0645\u06cc\u06ba (\u06af\u0627\u0631\u0688 \u06a9\u06cc \u062e\u0648\u062f \u0628\u0639\u062f \u06a9\u06d2 \u062d\u0635\u06d2 \u0645\u06cc\u06ba \u0648\u0636\u0627\u062d\u062a \u06a9\u06cc \u06af\u0626\u06cc \u06c1\u06d2):<\/p>\n<pre><code class=\"language-ts\">@Injectable()\nexport class JwtAuthGuard extends AuthGuard('jwt') {\n  handleRequest(err: any, user: any, info: any) {\n    if (info?.name === 'TokenExpiredError') {\n      throw new UnauthorizedException({\n        message: 'Access token expired',\n        code: 'TOKEN_EXPIRED',\n      });\n    }\n\n    if (err || !user) {\n      throw new UnauthorizedException({\n        message: 'Unauthorized',\n        code: 'UNAUTHORIZED',\n      });\n    }\n\n    return user;\n  }\n}\n<\/code><\/pre>\n<p>\u06cc\u06c1\u0627\u06ba\u060c <code>info<\/code> \u062c\u06d2 \u0688\u0628\u0644\u06cc\u0648 \u0679\u06cc \u0644\u0627\u0626\u0628\u0631\u06cc\u0631\u06cc \u0646\u06d2 \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u0645\u0633\u062a\u0631\u062f \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0648\u062c\u06c1 \u06a9\u0648 \u067e\u0627\u0633 \u06a9\u06cc\u0627\u06d4 \u0627\u06af\u0631 <code>TokenExpiredError<\/code>\u0645\u062d\u0627\u0641\u0638 \u062c\u0648\u0627\u0628 \u062f\u06cc\u062a\u0627 \u06c1\u06d2: <code>401<\/code> \u0627\u0648\u0631 \u0645\u0634\u06cc\u0646 \u067e\u0691\u06be\u0646\u06d2 \u06a9\u06d2 \u0642\u0627\u0628\u0644 <code>code<\/code> \u06a9\u06cc <code>TOKEN_EXPIRED<\/code>. \u062f\u06cc\u06af\u0631 \u063a\u0644\u0637\u06cc\u0627\u06ba (\u0679\u0648\u06a9\u0646 \u063a\u0627\u0626\u0628 \u06cc\u0627 \u063a\u0644\u0637) \u06a9\u06d2 \u0646\u062a\u06cc\u062c\u06d2 \u0645\u06cc\u06ba \u0645\u062e\u062a\u0644\u0641 \u06a9\u0648\u0688 \u06c1\u0648\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u067e\u06be\u0631 \u06a9\u0648\u0646\u06cc\u06cc \u067e\u0691\u06be \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 <code>error.error.code<\/code> \u0627\u06cc\u0631\u0631 \u06c1\u06cc\u0646\u0688\u0644\u0631 \u0645\u06cc\u06ba\u060c \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u0635\u0631\u0641 \u0627\u0633 \u0635\u0648\u0631\u062a \u0645\u06cc\u06ba \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0631\u06cc\u06ba \u0627\u06af\u0631 \u0622\u067e \u06a9\u0627 \u06a9\u0648\u0688 \u06cc\u06c1 \u0628\u062a\u0627\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u0627\u0633 \u06a9\u06cc \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648 \u06af\u0626\u06cc \u06c1\u06d2\u06d4<\/p>\n<p>\u062f\u0648\u0633\u0631\u0627 \u0622\u067e\u0634\u0646 \u06a9\u0644\u0627\u0626\u0646\u0679 \u067e\u0631 \u06c1\u06d2\u06d4 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u06a9\u0627 \u067e\u06d2 \u0644\u0648\u0688 \u063a\u06cc\u0631 \u062e\u0641\u06cc\u06c1 \u06a9\u0631\u062f\u06c1 \u06c1\u06d2\u060c \u0644\u06c1\u0630\u0627 \u06a9\u0648\u0646\u06cc\u06cc \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u0688\u06cc \u06a9\u0648\u0688 \u0627\u0648\u0631 \u067e\u0691\u06be \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 <code>exp<\/code> (\u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645) \u0627\u0633 \u0628\u0627\u062a \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u062f\u0639\u0648\u06d2 \u06a9\u06c1 \u06cc\u06c1 \u062c\u0644\u062f \u06c1\u06cc \u062e\u062a\u0645 \u06c1\u0648 \u062c\u0627\u0626\u06d2 \u06af\u0627\u06d4 \u0644\u06cc\u06a9\u0646 \u06a9\u0644\u0627\u0626\u0646\u0679 \u06a9\u06cc \u06af\u06be\u0691\u06cc \u063a\u0644\u0637 \u06c1\u0648 \u0633\u06a9\u062a\u06cc \u06c1\u06d2\u060c \u0627\u0633 \u0644\u06cc\u06d2 \u0633\u0631\u0648\u0631 \u06a9\u0627 \u062c\u0648\u0627\u0628 \u0627\u0628 \u0628\u06be\u06cc \u0645\u0633\u062a\u0646\u062f \u06c1\u06d2\u06d4<\/p>\n<p><strong>\u0679\u0648\u06a9\u0646 \u06a9\u06cc \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648\u0646\u06d2 \u067e\u0631 \u0627\u0646\u06af\u0648\u0644\u0631 \u06a9\u0648 \u06a9\u06cc\u0627 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u061f<\/strong> \u0639\u0627\u0645 \u0627\u0644\u0641\u0627\u0638 \u0645\u06cc\u06ba \u06cc\u06c1 \u0645\u0631\u0627\u062d\u0644 \u06c1\u06cc\u06ba:<\/p>\n<ol>\n<li>\u0645\u062d\u0641\u0648\u0638 \u0627\u062e\u062a\u062a\u0627\u0645\u06cc \u0645\u0642\u0627\u0645\u0627\u062a \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u0627\u0633 \u0637\u0631\u062d \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648\u062a\u06cc \u06c1\u06cc\u06ba: <code>401<\/code>\u062c\u0648\u0627\u0628 \u0645\u06cc\u06ba \u06a9\u06c1\u0627 \u06af\u06cc\u0627 \u06c1\u06d2 \u06a9\u06c1 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648 \u06af\u0626\u06cc \u06c1\u06d2\u06d4<\/li>\n<li>\u0635\u0627\u0631\u0641 \u06a9\u0648 \u063a\u0644\u0637\u06cc \u0638\u0627\u06c1\u0631 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2 \u06a9\u0648\u0646\u06cc\u06cc \u0631\u0648\u06a9\u062a\u0627 \u06c1\u06d2 \u0646\u0627\u06a9\u0627\u0645 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u0648\u06d4<\/li>\n<li>\u06a9\u0648\u0646\u06cc\u06cc \u06a9\u0627\u0644 <code>POST \/auth\/refresh<\/code>. \u0628\u0631\u0627\u0624\u0632\u0631 \u062e\u0648\u062f \u0628\u062e\u0648\u062f HttpOnly \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0648\u06a9\u06cc\u0632 \u0645\u0646\u0633\u0644\u06a9 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0627\u0633 \u06a9\u06cc \u0648\u062c\u06c1 \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u0627\u0646\u06af\u0648\u0644\u0631 \u06a9\u0648\u06a9\u06cc\u0632 \u06a9\u0648 \u0646\u06c1\u06cc\u06ba \u067e\u0691\u06be \u0633\u06a9\u062a\u0627 \u0627\u0648\u0631 \u0646\u06c1 \u06c1\u06cc \u0627\u0646\u06c1\u06cc\u06ba \u062e\u0648\u062f \u0634\u0627\u0645\u0644 \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4<\/li>\n<li>\u0628\u06cc\u06a9 \u0627\u06cc\u0646\u0688 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0633\u06d2 \u06af\u06be\u0645\u0627\u062a\u0627 \u06c1\u06d2\u060c \u0627\u06cc\u06a9 \u0646\u0626\u06cc \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0648\u06a9\u06cc \u0633\u06cc\u0679 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u0627\u06cc\u06a9 \u0646\u06cc\u0627 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u0644\u0648\u0679\u0627\u062a\u0627 \u06c1\u06d2\u06d4<\/li>\n<li>\u06a9\u0648\u0646\u06cc\u06cc \u0646\u06cc\u0627 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u0645\u06cc\u0645\u0648\u0631\u06cc \u0645\u06cc\u06ba \u0627\u0633\u0679\u0648\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/li>\n<li>\u06a9\u0648\u0646\u06cc\u06cc \u0627\u0635\u0644 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06cc \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0633 \u0628\u0627\u0631 \u0646\u0626\u06d2 \u0679\u0648\u06a9\u0646 \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2\u060c \u0627\u0648\u0631 \u0646\u062a\u06cc\u062c\u06c1 \u06a9\u0648 \u062c\u0632\u0648 \u06a9\u0648 \u0627\u0633 \u0637\u0631\u062d \u0645\u0646\u062a\u0642\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u062c\u06cc\u0633\u06d2 \u06a9\u0686\u06be \u06c1\u0648\u0627 \u06c1\u06cc \u0646\u06c1 \u06c1\u0648\u06d4<\/li>\n<li>\u0627\u06af\u0631 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0627\u0644 \u062e\u0648\u062f \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648 \u062c\u0627\u062a\u06cc \u06c1\u06d2 (\u0645\u062b\u0627\u0644 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631\u060c \u0627\u06af\u0631 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648 \u062c\u0627\u062a\u06cc \u06c1\u06d2\u060c \u0627\u0633\u06d2 \u0645\u0646\u0633\u0648\u062e \u06a9\u0631 \u062f\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u060c \u06cc\u0627 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2)\u060c \u0627\u0646\u06af\u0648\u0644\u0631 \u0627\u0646 \u0645\u06cc\u0645\u0648\u0631\u06cc \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u0635\u0627\u0641 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u06a9\u0631\u0646\u0627 \u0628\u0646\u062f \u06a9\u0631 \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u0635\u0627\u0631\u0641 \u06a9\u0648 \u0644\u0627\u06af \u0627\u0646 \u0635\u0641\u062d\u06c1 \u067e\u0631 \u0648\u0627\u067e\u0633 \u0628\u06be\u06cc\u062c \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4<\/li>\n<\/ol>\n<p>\u06cc\u06c1\u0627\u06ba \u062f\u0648 \u062d\u0641\u0627\u0638\u062a\u06cc \u062a\u062f\u0627\u0628\u06cc\u0631 \u0627\u06c1\u0645 \u06c1\u06cc\u06ba\u06d4 <code>401<\/code> \u0633\u06d2 <code>\/auth\/login<\/code> \u06cc\u0627 <code>\/auth\/refresh<\/code> (\u06c1\u0645\u06cc\u0634\u06c1 \u06a9\u06d2 \u0644\u06cc\u06d2 \u062f\u06c1\u0631\u0627\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2) \u06c1\u0631 \u0627\u0635\u0644 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u0648 \u0635\u0631\u0641 \u0627\u06cc\u06a9 \u0628\u0627\u0631 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0622\u0632\u0645\u0627\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<h3 id=\"heading-the-concurrency-problem\">\u06c1\u0645 \u0622\u06c1\u0646\u06af\u06cc \u06a9\u06d2 \u0645\u0633\u0627\u0626\u0644<\/h3>\n<p>\u0641\u0631\u0636 \u06a9\u0631\u06cc\u06ba \u06a9\u06c1 \u0622\u067e \u06a9\u06d2 \u067e\u0627\u0633 \u067e\u0627\u0646\u0686 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-text\">GET \/users\nGET \/products\nGET \/orders\nGET \/profile\nGET \/notifications\n<\/code><\/pre>\n<p>\u06c1\u0631 \u0627\u06cc\u06a9 \u06a9\u0648 401 \u0645\u0644\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0627\u06af\u0631 \u0622\u067e \u0627\u0633 \u06a9\u06cc \u062d\u0641\u0627\u0638\u062a \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba \u062a\u0648\u060c \u06cc\u06c1\u0627\u06ba \u06a9\u06cc\u0627 \u06c1\u0648\u062a\u0627 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-text\">Request A \u2192 refresh R1\nRequest B \u2192 refresh R1\nRequest C \u2192 refresh R1\nRequest D \u2192 refresh R1\nRequest E \u2192 refresh R1\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u0622\u0633\u0627\u0646\u06cc \u0633\u06d2 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4 \u0688\u06cc\u0634 \u0628\u0648\u0631\u0688 \u06a9\u06d2 \u0635\u0641\u062d\u0627\u062a \u0627\u06a9\u062b\u0631 \u0627\u06cc\u06a9 \u06c1\u06cc \u0648\u0642\u062a \u0645\u06cc\u06ba \u0645\u062a\u0639\u062f\u062f API \u06a9\u0627\u0644\u0632 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u0648\u0631 \u0648\u06c1 \u0633\u0628\u06be\u06cc \u0627\u06cc\u06a9 \u06c1\u06cc \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u067e\u0627\u0633 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u0633 \u0644\u06cc\u06d2 \u0648\u06c1 \u0633\u0628 \u0627\u06cc\u06a9 \u06c1\u06cc \u0648\u0642\u062a \u0645\u06cc\u06ba \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648\u062c\u0627\u062a\u06d2 \u06c1\u06cc\u06ba \u062c\u0628 \u0627\u0646 \u06a9\u06cc \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648\u062c\u0627\u062a\u06cc \u06c1\u06d2\u06d4 \u06c1\u0631 \u0646\u0627\u06a9\u0627\u0645 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0622\u0632\u0627\u062f\u0627\u0646\u06c1 \u0637\u0648\u0631 \u067e\u0631 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0627 \u0641\u06cc\u0635\u0644\u06c1 \u06a9\u0631\u062a\u06cc \u06c1\u06d2 \u0627\u0648\u0631 \u06c1\u0631 \u0627\u06cc\u06a9 \u0648\u06c1\u06cc \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0648\u06a9\u06cc R1 \u0628\u06be\u06cc\u062c\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0644\u06cc\u06a9\u0646 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u06af\u0631\u062f\u0634 \u06a9\u06c1\u062a\u06cc \u06c1\u06d2:<\/p>\n<pre><code class=\"language-text\">R1 \u2192 R2\n<\/code><\/pre>\n<p>\u0627\u0633 \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 \u06a9\u06c1 \u06c1\u0631 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0648\u0627\u062d\u062f \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06c1\u06d2\u06d4 \u067e\u06c1\u0644\u06cc \u0631\u06cc\u0641\u0631\u06cc\u0634 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u062c\u0648 \u0633\u0631\u0648\u0631 \u0633\u06d2 \u0679\u06a9\u0631\u0627\u062a\u06cc \u06c1\u06d2 \u0648\u06c1 R1 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06cc \u06c1\u06d2 \u0627\u0648\u0631 \u0628\u062f\u0644\u06d2 \u0645\u06cc\u06ba R2 \u062d\u0627\u0635\u0644 \u06a9\u0631\u062a\u06cc \u06c1\u06d2\u06d4 R1 \u0627\u0628 \u0628\u0637\u0648\u0631 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u062f\u06a9\u06be\u0627\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2\u06d4 \u0628\u0627\u0642\u06cc \u0686\u0627\u0631 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba R1 \u0644\u06d2 \u06a9\u0631 \u0622\u062a\u06cc \u06c1\u06cc\u06ba\u060c \u062c\u0633\u06d2 \u0633\u0631\u0648\u0631 \u067e\u06c1\u0644\u06d2 \u0633\u06d2 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u0634\u062f\u06c1 \u0679\u0648\u06a9\u0646 \u0633\u0645\u062c\u06be\u062a\u0627 \u06c1\u06d2\u06d4 \u0628\u06c1\u062a\u0631\u06cc\u0646 \u0637\u0648\u0631 \u067e\u0631\u060c \u06cc\u06c1 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u0645\u0633\u062a\u0631\u062f \u06a9\u0631 \u062f\u06cc \u062c\u0627\u062a\u06cc \u06c1\u06cc\u06ba \u0627\u0648\u0631 \u0635\u0627\u0631\u0641 \u06a9\u0648 \u0628\u063a\u06cc\u0631 \u06a9\u0633\u06cc \u0645\u0639\u0642\u0648\u0644 \u0648\u062c\u06c1 \u06a9\u06d2 \u0644\u0627\u06af \u0622\u0624\u0679 \u06a9\u0631 \u062f\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u0628\u062f\u062a\u0631\u06cc\u0646 \u0635\u0648\u0631\u062a \u0645\u06cc\u06ba\u060c \u0633\u0631\u0648\u0631 \u0627\u0633\u06d2 \u0679\u0648\u06a9\u0646 \u0686\u0648\u0631\u06cc \u0633\u0645\u062c\u06be\u06d2 \u06af\u0627 (\u06c1\u0645 \u0628\u0639\u062f \u0645\u06cc\u06ba \u062f\u0648\u0628\u0627\u0631\u06c1 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u06cc \u06a9\u06be\u0648\u062c \u06a9\u0627 \u0627\u062d\u0627\u0637\u06c1 \u06a9\u0631\u06cc\u06ba \u06af\u06d2) \u0627\u0648\u0631 \u067e\u0648\u0631\u06d2 \u0633\u06cc\u0634\u0646 \u06a9\u0648 \u0645\u0646\u0633\u0648\u062e \u06a9\u0631 \u062f\u06d2 \u06af\u0627\u06d4<\/p>\n<p>\u0644\u06c1\u0630\u0627 &quot;\u0635\u0631\u0641 \u0627\u06cc\u06a9 \u06a9\u0648 R1 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2&#8221; \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 \u06a9\u06c1 R1 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0635\u0631\u0641 \u0627\u06cc\u06a9 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0628\u06be\u06cc\u062c\u06cc \u062c\u0627\u0646\u06cc \u0686\u0627\u06c1\u06cc\u06d2\u060c \u0627\u0648\u0631 \u062f\u06cc\u06af\u0631 \u062a\u0645\u0627\u0645 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u062c\u0646 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0646\u0626\u06d2 \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2 \u0627\u0633 \u0648\u0627\u062d\u062f \u0646\u062a\u06cc\u062c\u06c1 \u06a9\u0627 \u0627\u0646\u062a\u0638\u0627\u0631 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<p>\u0644\u06c1\u0630\u0627 \u0627\u06cc\u06a9 \u0645\u0634\u062a\u0631\u06a9\u06c1 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0622\u067e\u0631\u06cc\u0634\u0646 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2\u06d4<\/p>\n<h3 id=\"heading-angular-refresh-lock\">\u06a9\u0648\u0646\u06cc\u06cc \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0644\u0627\u06a9<\/h3>\n<p>\u0631\u06cc\u0641\u0631\u06cc\u0634 \u0644\u0627\u06a9\u0646\u06af Angular \u0627\u06cc\u067e\u0633 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06cc\u06c1 \u06cc\u0642\u06cc\u0646\u06cc \u0628\u0646\u0627\u0646\u06d2 \u06a9\u0627 \u0627\u06cc\u06a9 \u0637\u0631\u06cc\u0642\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u0627\u06cc\u06a9 \u0648\u0642\u062a \u0645\u06cc\u06ba \u0635\u0631\u0641 \u0627\u06cc\u06a9 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u062c\u0627\u0631\u06cc \u06c1\u06d2\u06d4 \u06cc\u06c1 \u0627\u06cc\u06a9 \u062d\u0642\u06cc\u0642\u06cc \u0622\u067e\u0631\u06cc\u0679\u0646\u06af \u0633\u0633\u0679\u0645 \u0644\u0627\u06a9 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u0627\u0633 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2\u060c \u0633\u0631\u0648\u0633 \u0627\u06cc\u06a9 \u0645\u062a\u063a\u06cc\u0631 \u06c1\u06d2 (<code>refreshInProgress$<\/code>) \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u0686\u0644\u062a\u06d2 \u0648\u0642\u062a \u0631\u06a9\u06be\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<ul>\n<li>\u067e\u06c1\u0644\u06d2 \u06a9\u0627\u0644 \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u06a9\u0648 \u067e\u062a\u06c1 \u0686\u0644\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u0645\u062a\u063a\u06cc\u0631 \u062e\u0627\u0644\u06cc \u06c1\u06d2\u060c \u0627\u06cc\u06a9 HTTP \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0634\u0631\u0648\u0639 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u067e\u06be\u0631 \u0627\u0633\u06d2 \u0645\u062a\u063a\u06cc\u0631 \u0645\u06cc\u06ba \u0627\u0633\u0679\u0648\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/li>\n<li>\u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u06d2 \u0686\u0644\u0646\u06d2 \u06a9\u06d2 \u062f\u0648\u0631\u0627\u0646 \u0622\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u062f\u06cc\u06af\u0631 \u06a9\u0627\u0644 \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u0645\u062a\u063a\u06cc\u0631 \u06a9\u0648 \u067e\u0627\u067e\u0648\u0644\u0688 \u067e\u0627\u0626\u06cc\u06ba \u06af\u06d2 \u0627\u0648\u0631 \u0646\u0626\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0634\u0631\u0648\u0639 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0648\u06c1\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0648\u0635\u0648\u0644 \u06a9\u0631\u06cc\u06ba \u06af\u06d2\u06d4<\/li>\n<li><code>shareReplay(1)<\/code>    \u062a\u0645\u0627\u0645 \u06a9\u0627\u0644 \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u0648\u06ba \u06a9\u0648 \u0627\u06cc\u06a9 \u0646\u062a\u06cc\u062c\u06c1 \u06a9\u0627 \u0627\u0634\u062a\u0631\u0627\u06a9 \u06a9\u0631\u0646\u06d2 \u067e\u0631 \u0645\u062c\u0628\u0648\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u06cc\u06c1\u0627\u06ba \u062a\u06a9 \u06a9\u06c1 \u0627\u06af\u0631 \u0622\u067e \u062a\u06be\u0648\u0691\u06cc \u062f\u06cc\u0631 \u0633\u06d2 \u0633\u0628\u0633\u06a9\u0631\u0627\u0626\u0628 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u06c1\u0631 \u0627\u06cc\u06a9 \u06a9\u0648 \u0648\u06c1\u06cc \u0646\u06cc\u0627 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u0645\u0644\u062a\u0627 \u06c1\u06d2\u06d4<\/li>\n<li><code>finalize()<\/code>    \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0645\u06a9\u0645\u0644 \u06c1\u0648\u0646\u06d2 \u06a9\u06d2 \u0628\u0639\u062f \u06cc\u06c1 \u0645\u062a\u063a\u06cc\u0631 \u06a9\u0648 \u0635\u0627\u0641 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0644\u06c1\u0630\u0627 \u0622\u067e \u0628\u0639\u062f \u0645\u06cc\u06ba \u0627\u0633 \u06a9\u06cc \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648\u0646\u06d2 \u067e\u0631 \u0627\u0633\u06d2 \u062a\u0627\u0632\u06c1 \u06a9\u0631\u0646\u0627 \u0634\u0631\u0648\u0639 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/li>\n<\/ul>\n<pre><code class=\"language-ts\">private refreshInProgress$:\n  Observable<string> | null = null;\n\nrefreshAccessToken():\n  Observable<string> {\n\n  if (this.refreshInProgress$) {\n    return this.refreshInProgress$;\n  }\n\n  this.refreshInProgress$ =\n    this.http\n      .post<loginresponse>(\n        `${this.apiUrl}\/refresh`,\n        {},\n        {\n          withCredentials: true,\n        },\n      )\n      .pipe(\n        map(response => {\n          this.setAccessToken(\n            response.accessToken,\n          );\n\n          return response.accessToken;\n        }),\n\n        finalize(() => {\n          this.refreshInProgress$ = null;\n        }),\n\n        shareReplay(1),\n      );\n\n  return this.refreshInProgress$;\n}\n<\/loginresponse><\/string><\/string><\/code><\/pre>\n<p>\u0646\u062a\u06cc\u062c\u06d2 \u06a9\u06cc \u0633\u0627\u062e\u062a \u06cc\u06c1 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-text\">A \u2500\u2510\nB \u2500\u2524\nC \u2500\u253c\u2500\u2500\u2192 one refresh request\nD \u2500\u2524\nE \u2500\u2518\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u0644\u0627\u06a9 \u0627\u0633 \u0628\u0627\u062a \u06a9\u0648 \u06cc\u0642\u06cc\u0646\u06cc \u0628\u0646\u0627\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u0627\u06cc\u06a9 \u06c1\u06cc Angular \u0627\u06cc\u067e\u0644\u06cc \u06a9\u06cc\u0634\u0646 \u0645\u062b\u0627\u0644 \u0633\u06d2 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u0627\u06cc\u06a9 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0622\u067e\u0631\u06cc\u0634\u0646 \u06a9\u0627 \u0627\u0634\u062a\u0631\u0627\u06a9 \u06a9\u0631\u062a\u06cc \u06c1\u06cc\u06ba\u06d4 \u06cc\u06c1 \u0639\u0644\u06cc\u062d\u062f\u06c1 \u0628\u0631\u0627\u0624\u0632\u0631 \u0679\u06cc\u0628\u0632 \u06a9\u0648 \u0645\u0631\u0628\u0648\u0637 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0633\u0631\u0648\u0631 \u067e\u0631 \u0627\u06cc\u0679\u0645 \u0679\u0648\u06a9\u0646 \u06af\u0631\u062f\u0634 \u06a9\u0627 \u0645\u062a\u0628\u0627\u062f\u0644 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u067e\u0633\u062f\u06cc\u062f \u06a9\u0648 \u06cc\u0642\u06cc\u0646\u06cc \u0628\u0646\u0627\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2 \u06a9\u06c1 \u0635\u0631\u0641 \u0627\u06cc\u06a9 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0627\u06cc\u06a9 \u062e\u0627\u0635 \u0641\u0639\u0627\u0644 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631 \u0633\u06a9\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<h3 id=\"heading-refresh-endpoint\">\u0627\u062e\u062a\u062a\u0627\u0645\u06cc \u067e\u0648\u0627\u0626\u0646\u0679\u0633 \u06a9\u0648 \u062a\u0627\u0632\u06c1 \u06a9\u0631\u06cc\u06ba\u06d4<\/h3>\n<p>\u0631\u06cc\u0641\u0631\u06cc\u0634 \u0627\u06cc\u0646\u0688 \u067e\u0648\u0627\u0626\u0646\u0679 \u06a9\u0648 \u0644\u0627\u0632\u0645\u06cc \u0637\u0648\u0631 \u067e\u0631 \u06a9\u0648\u06a9\u06cc\u0632 \u06a9\u0648 \u067e\u0691\u06be\u0646\u0627\u060c \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062f\u06c1 \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u06c1\u06cc\u0634 \u06a9\u0631\u0646\u0627\u060c \u0645\u0645\u0627\u062b\u0644 \u0627\u06cc\u06a9\u0679\u0648 \u0631\u06cc\u06a9\u0627\u0631\u0688\u0632 \u062a\u0644\u0627\u0634 \u06a9\u0631\u0646\u0627\u060c \u0679\u0648\u06a9\u0646 \u0627\u0648\u0631 \u0633\u06cc\u0634\u0646 \u06a9\u06cc \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648\u0646\u06d2\/\u0645\u0646\u0633\u0648\u062e \u06a9\u0648 \u0686\u06cc\u06a9 \u06a9\u0631\u0646\u0627\u060c \u0627\u0648\u0631 \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u0645\u062d\u0641\u0648\u0638 \u0637\u0631\u06cc\u0642\u06d2 \u0633\u06d2 \u06af\u06be\u0645\u0627\u0646\u0627\u06d4 \u0645\u0632\u06cc\u062f \u0628\u0631\u0622\u06ba\u060c \u0622\u067e \u06a9\u0648 \u0627\u06cc\u06a9 \u0646\u06cc\u0627 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u0648\u0627\u067e\u0633 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2 \u0627\u0648\u0631 \u0633\u0631\u0648\u0631 \u0633\u0627\u0626\u06cc\u0688 \u0622\u067e\u0631\u06cc\u0634\u0646 \u06a9\u0627\u0645\u06cc\u0627\u0628 \u06c1\u0648\u0646\u06d2 \u06a9\u06d2 \u0628\u0639\u062f \u06c1\u06cc \u0641\u0627\u0644 \u0628\u06cc\u06a9 \u06a9\u0648\u06a9\u06cc \u0633\u06cc\u0679 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<p>\u067e\u0633\u062f\u06cc\u062f \u0648\u0635\u0648\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-text\">refresh_token cookie\n<\/code><\/pre>\n<p>\u067e\u06be\u0631:<\/p>\n<pre><code class=\"language-text\">Cookie\n \u2193\nSHA-256\n \u2193\nFind RefreshToken\n \u2193\nCheck revokedAt\n \u2193\nCheck expiration\n \u2193\nFind Session\n \u2193\nCheck Session\n \u2193\nRotate\n \u2193\nNew Access Token\n<\/code><\/pre>\n<p>\u06cc\u06c1\u0627\u06ba \u06c1\u0631 \u0642\u062f\u0645 \u0645\u06cc\u06ba \u06a9\u06cc\u0627 \u06c1\u0648\u062a\u0627 \u06c1\u06d2:<\/p>\n<ol>\n<li>\u06a9\u0648\u06a9\u06cc \u067e\u0691\u06be\u06cc\u06ba: \u0628\u0631\u0627\u0624\u0632\u0631 \u0646\u06d2 \u0627\u06cc\u06a9 \u062e\u0627\u0645 \u06a9\u0648\u06a9\u06cc \u06a9\u0648 \u0645\u0646\u0633\u0644\u06a9 \u06a9\u06cc\u0627\u06d4 <code>refresh_token<\/code> \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u067e\u0631\u06d4 \u0633\u0631\u0648\u0631 \u0627\u0633\u06d2 \u0622\u0646\u06d2 \u0648\u0627\u0644\u06cc \u06a9\u0648\u06a9\u06cc \u0633\u06d2 \u067e\u0691\u06be\u062a\u0627 \u06c1\u06d2\u06d4<\/li>\n<li>\u06c1\u06cc\u0634: \u0633\u0631\u0648\u0631 SHA-256 \u06c1\u06cc\u0634 \u06a9\u0627 \u062d\u0633\u0627\u0628 \u0644\u06af\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0633 \u06a9\u06cc \u0648\u062c\u06c1 \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u0645\u06cc\u06ba \u0635\u0631\u0641 \u06c1\u06cc\u0634 \u06c1\u0648\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u062e\u0627\u0645 \u0679\u0648\u06a9\u0646 \u0646\u06c1\u06cc\u06ba\u06d4<\/li>\n<li>\u0631\u06cc\u06a9\u0627\u0631\u0688 \u062a\u0644\u0627\u0634 \u06a9\u0631\u06cc\u06ba: \u0627\u0633 \u06a9\u06d2 \u06c1\u06cc\u0634 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06c1 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u062a\u0644\u0627\u0634 \u06a9\u0631\u06cc\u06ba\u06d4 \u06a9\u0648\u0626\u06cc \u0645\u0645\u0627\u062b\u0644\u062a \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 \u06a9\u06c1 \u0679\u0648\u06a9\u0646 \u0646\u0627\u0645\u0639\u0644\u0648\u0645 \u06c1\u06d2 \u0627\u0648\u0631 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0645\u0633\u062a\u0631\u062f \u06a9\u0631 \u062f\u06cc \u06af\u0626\u06cc \u06c1\u06d2\u06d4<\/li>\n<li>\u0686\u06cc\u06a9 \u06a9\u0631\u06cc\u06ba <code>revokedAt<\/code>: \u0627\u06af\u0631 \u0679\u0648\u06a9\u0646 \u067e\u06c1\u0644\u06d2 \u06c1\u06cc \u0645\u0646\u0633\u0648\u062e \u06cc\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u06cc\u0627 \u062c\u0627 \u0686\u06a9\u0627 \u06c1\u06d2\u060c \u062a\u0648 \u0627\u0633\u06d2 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u06cc\u0627 \u062c\u0627 \u0633\u06a9\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0633\u0631\u0648\u0631 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0627 \u067e\u062a\u06c1 \u0644\u06af\u0627\u0646\u06d2 \u06a9\u06cc \u067e\u0627\u0644\u06cc\u0633\u06cc \u067e\u0631 \u0639\u0645\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u062c\u0633 \u06a9\u06cc \u062c\u0644\u062f \u06c1\u06cc \u0648\u0636\u0627\u062d\u062a \u06a9\u06cc \u062c\u0627\u0626\u06d2 \u06af\u06cc\u06d4<\/li>\n<li>\u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648\u0646\u06d2 \u06a9\u06cc \u062c\u0627\u0646\u0686 \u06a9\u0631\u06cc\u06ba: \u0645\u0639\u06cc\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646\u0632 \u06a9\u0648 \u0645\u0633\u062a\u0631\u062f \u06a9\u0631 \u062f\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0635\u0627\u0631\u0641 \u06a9\u0648 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0644\u0627\u06af \u0627\u0646 \u06a9\u0631\u0646\u0627 \u06c1\u0648\u06af\u0627\u06d4<\/li>\n<li>\u0633\u06cc\u0634\u0646 \u062a\u0644\u0627\u0634 \u06a9\u0631\u0646\u0627 \u0627\u0648\u0631 \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0631\u0646\u0627: \u0679\u0648\u06a9\u0646\u0632 <code>sessionId<\/code> \u0627\u06cc\u06a9 \u0633\u06cc\u0634\u0646 \u06a9\u06cc \u0637\u0631\u0641 \u0627\u0634\u0627\u0631\u06c1 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u06af\u0631 \u0648\u06c1 \u0633\u06cc\u0634\u0646 \u063a\u0627\u0626\u0628\u060c \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645\u060c \u06cc\u0627 \u0645\u0646\u0633\u0648\u062e \u06c1\u0648 \u06af\u06cc\u0627 \u06c1\u06d2 (\u0645\u062b\u0644\u0627\u064b \u0644\u0627\u06af \u0622\u0624\u0679 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0628\u0639\u062f)\u060c \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0645\u0633\u062a\u0631\u062f \u06a9\u0631 \u062f\u06cc \u062c\u0627\u0626\u06d2 \u06af\u06cc \u0686\u0627\u06c1\u06d2 \u0679\u0648\u06a9\u0646 \u06c1\u06cc \u0679\u06be\u06cc\u06a9 \u0646\u0638\u0631 \u0622\u0626\u06d2\u06d4<\/li>\n<li>\u06af\u0631\u062f\u0634: \u0633\u0631\u0648\u0631 \u067e\u0631\u0627\u0646\u06d2 \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u0628\u0637\u0648\u0631 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u0646\u0634\u0627\u0646 \u0632\u062f \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u06a9\u0646\u06cc\u06a9\u0679 \u06a9\u0631\u0646\u06d2 \u0633\u06d2 \u067e\u06c1\u0644\u06d2 \u0627\u0633\u06cc \u0633\u06cc\u0634\u0646 \u0645\u06cc\u06ba \u0627\u06cc\u06a9 \u0646\u06cc\u0627 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u062a\u06cc\u0627\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/li>\n<li>\u062c\u0648\u0627\u0628: \u0633\u0631\u0648\u0631 HttpOnly \u06a9\u0648\u06a9\u06cc \u0645\u06cc\u06ba \u0627\u06cc\u06a9 \u0646\u06cc\u0627 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0633\u06cc\u0679 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0631\u0633\u067e\u0627\u0646\u0633 \u0628\u0627\u0688\u06cc \u0645\u06cc\u06ba \u0627\u06cc\u06a9 \u0646\u06cc\u0627 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u0644\u0648\u0679\u0627\u062a\u0627 \u06c1\u06d2\u06d4<\/li>\n<\/ol>\n<h2 id=\"heading-17-refresh-token-rotation\">17. \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u06af\u0631\u062f\u0634 \u06a9\u0648 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0631\u06cc\u06ba\u06d4<\/h2>\n<p>\u062a\u0628\u062f\u06cc\u0644\u06cc \u0627\u06cc\u06a9 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u062c\u06af\u06c1 \u0644\u06d2 \u0644\u06cc\u062a\u0627 \u06c1\u06d2 \u062c\u0628 \u0627\u0633\u06d2 \u06a9\u0627\u0645\u06cc\u0627\u0628\u06cc \u0633\u06d2 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u067e\u0631\u0627\u0646\u06d2 \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u0627\u0633\u06cc \u0645\u0646\u0637\u0642\u06cc \u0639\u0645\u0644 \u06a9\u06d2 \u062d\u0635\u06d2 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0646\u0627\u0642\u0627\u0628\u0644 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u0628\u0646\u0627\u06cc\u0627 \u062c\u0627\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2 \u062c\u0648 \u0645\u062a\u0628\u0627\u062f\u0644 \u062a\u062e\u0644\u06cc\u0642 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0628\u0635\u0648\u0631\u062a \u062f\u06cc\u06af\u0631\u060c \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634\u0648\u06ba \u06cc\u0627 \u06c1\u0645 \u0622\u06c1\u0646\u06af\u06cc \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u06cc \u0648\u062c\u06c1 \u0633\u06d2 \u0633\u06cc\u0634\u0646 \u06a9\u06cc \u062d\u0627\u0644\u062a \u0645\u062a\u0636\u0627\u062f \u06c1\u0648 \u0633\u06a9\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<p>\u0641\u0631\u0636 \u06a9\u0631\u06cc\u06ba \u06a9\u06c1 R1 \u0641\u06cc \u0627\u0644\u062d\u0627\u0644 \u0641\u0639\u0627\u0644 \u06c1\u06d2\u06d4 \u06a9\u0644\u0627\u0626\u0646\u0679 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06c1\u0648\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0633\u0631\u0648\u0631 R2 \u062a\u06cc\u0627\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0627\u0633 \u0645\u0642\u0627\u0645 \u067e\u0631\u060c \u0633\u0631\u0648\u0631 \u06c1\u0645\u06cc\u06ba \u062f\u0648 \u0686\u06cc\u0632\u06cc\u06ba \u0628\u062a\u0627\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u067e\u0631\u0627\u0646\u06d2 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u06a9\u0648 \u0627\u067e \u0688\u06cc\u0679 \u06a9\u0631\u062a\u0627 \u06c1\u06d2: \u06cc\u0639\u0646\u06cc \u06cc\u06c1 \u0627\u0628 \u062f\u0631\u0633\u062a \u0646\u06c1\u06cc\u06ba \u06c1\u06d2 \u0627\u0648\u0631 \u06a9\u0648\u0646 \u0633\u0627 \u0679\u0648\u06a9\u0646 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631 \u062f\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-text\">R1.revokedAt = now\nR1.replacedBy = R2\n<\/code><\/pre>\n<p>\u0627\u0628 \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u0686\u06be\u0648\u0679\u06cc \u0632\u0646\u062c\u06cc\u0631\u0648\u06ba \u06a9\u0648 \u0645\u062d\u0641\u0648\u0638 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 R1 R2 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u0641\u0627\u0631\u0648\u0631\u0688\u0646\u06af \u06a9\u06cc \u0637\u0631\u0641 \u0627\u0634\u0627\u0631\u06c1 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 <code>replacedBy<\/code>R2 \u0641\u06cc \u0627\u0644\u062d\u0627\u0644 \u0641\u0639\u0627\u0644 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-text\">R1\n \u2502\n \u2514\u2500\u2500 replacedBy \u2192 R2\n\nR2\n \u2502\n \u2514\u2500\u2500 active\n<\/code><\/pre>\n<p>\u0628\u0631\u0627\u0624\u0632\u0631 \u06a9\u0648 \u0646\u0626\u06cc \u06a9\u0648\u06a9\u06cc \u0645\u06cc\u06ba R2 \u0645\u0648\u0635\u0648\u0644 \u06c1\u0648\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0627\u0628 \u0633\u06d2 \u0635\u0631\u0641 R2 \u0628\u06be\u06cc\u062c\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0633\u06cc \u06a9\u0648 \u0627\u06af\u0644\u06d2 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u067e\u0631 \u062f\u06c1\u0631\u0627\u06cc\u0627 \u062c\u0627\u0626\u06d2 \u06af\u0627\u06d4 \u06cc\u0639\u0646\u06cc R2 \u06a9\u0648 \u0636\u0627\u0626\u0639 \u06a9\u0631 \u062f\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 R3 \u0627\u0633 \u06a9\u06cc \u062c\u06af\u06c1 \u0644\u06d2 \u0644\u06cc\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-text\">R2 \u2192 R3\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u0679\u0648\u06a9\u0646 \u0633\u0631\u06a9\u0648\u0644\u06cc\u0634\u0646 \u06c1\u06d2\u06d4 \u06a9\u0633\u06cc \u0628\u06be\u06cc \u0648\u0642\u062a\u060c \u0686\u06cc\u0646 \u067e\u0631 \u0628\u0627\u0644\u06a9\u0644 \u0627\u06cc\u06a9 \u0679\u0648\u06a9\u0646 \u062f\u0631\u0633\u062a \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u062a\u0645\u0627\u0645 \u067e\u0686\u06be\u0644\u06d2 \u0679\u0648\u06a9\u0646 \u0645\u0633\u062a\u0642\u0644 \u0637\u0648\u0631 \u067e\u0631 \u062a\u0628\u0627\u06c1 \u06c1\u0648 \u062c\u0627\u062a\u06d2 \u06c1\u06cc\u06ba \u0644\u06cc\u06a9\u0646 \u067e\u06be\u0631 \u0628\u06be\u06cc \u0645\u062d\u0641\u0648\u0638 \u0631\u06c1\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0645\u0631\u062f\u06c1 \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u0628\u0631\u0642\u0631\u0627\u0631 \u0631\u06a9\u06be\u0646\u06d2 \u0633\u06d2 \u062f\u0631\u062c \u0630\u06cc\u0644 \u062e\u0635\u0648\u0635\u06cc\u0627\u062a \u0642\u0627\u0628\u0644 \u0628\u0646\u062a\u06cc \u06c1\u06cc\u06ba:<\/p>\n<h3 id=\"heading-reuse-detection\">\u062f\u0648\u0628\u0627\u0631\u06c1 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0627 \u067e\u062a\u06c1 \u0644\u06af\u0627\u0646\u0627<\/h3>\n<p>\u0627\u06cc\u06a9 \u0679\u0648\u06a9\u0646 \u062c\u0648 \u067e\u06c1\u0644\u06d2 \u06c1\u06cc \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631 \u062f\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2 \u062f\u0648\u0628\u0627\u0631\u06c1 \u067e\u06cc\u0634 \u06a9\u0631\u0646\u0627 \u0686\u0648\u0631\u06cc \u06a9\u06cc \u0646\u0634\u0627\u0646\u062f\u06c1\u06cc \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u060c \u0644\u06cc\u06a9\u0646 \u06cc\u06c1 \u062c\u0627\u0626\u0632 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06d2 \u062a\u0646\u0627\u0632\u0639\u06c1 \u06cc\u0627 \u06a9\u06be\u0648\u0626\u06d2 \u06c1\u0648\u0626\u06d2 \u062c\u0648\u0627\u0628 \u06a9\u06d2 \u0628\u0639\u062f \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u06a9\u06cc \u0648\u062c\u06c1 \u0633\u06d2 \u0628\u06be\u06cc \u06c1\u0648 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 \u0633\u0631\u0648\u0631 \u06a9\u0648 \u0627\u0646 \u0645\u0639\u0627\u0645\u0644\u0627\u062a \u0645\u06cc\u06ba \u0641\u0631\u0642 \u06a9\u0631\u0646\u06d2 \u0627\u0648\u0631 \u0627\u0646 \u0633\u06d2 \u0646\u0645\u0679\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u0648\u0627\u0636\u062d \u067e\u0627\u0644\u06cc\u0633\u06cc \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2\u06d4<\/p>\n<p>\u0641\u0631\u0636 \u06a9\u0631\u06cc\u06ba \u06a9\u06c1 \u0627\u06cc\u06a9 \u062d\u0645\u0644\u06c1 \u0622\u0648\u0631 R1 \u0686\u0648\u0631\u06cc \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u067e\u06c1\u0644\u06d2 \u0633\u06d2 \u06c1\u06cc \u062c\u0627\u0626\u0632 \u0635\u0627\u0631\u0641\u06cc\u0646 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-text\">R1 \u2192 R2\n<\/code><\/pre>\n<p>\u0644\u06c1\u0630\u0627\u060c \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u0648 \u0645\u0646\u062f\u0631\u062c\u06c1 \u0630\u06cc\u0644 \u0631\u0627\u0633\u062a\u06d2 \u067e\u0631 \u0639\u0645\u0644 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u0626\u06d2:<\/p>\n<pre><code class=\"language-text\">R1.revokedAt != null\n<\/code><\/pre>\n<p>\u0627\u06af\u0631 R1 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0638\u0627\u06c1\u0631 \u06c1\u0648\u062a\u0627 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-text\">POST \/auth\/refresh\nCookie: R1\n<\/code><\/pre>\n<p>\u06c1\u0645 \u0627\u0633\u06d2 \u0642\u0627\u0628\u0644 \u0627\u0639\u062a\u0631\u0627\u0636 \u0679\u0648\u06a9\u0646 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u0633\u0645\u062c\u06be\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u0633\u062e\u062a \u0631\u062f\u0639\u0645\u0644 \u067e\u0648\u0631\u06d2 \u0627\u062c\u0644\u0627\u0633 \u06a9\u0648 \u0645\u0646\u0633\u0648\u062e \u06a9\u0631\u0646\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u062a\u0648:<\/p>\n<pre><code class=\"language-text\">Session A\n \u251c\u2500\u2500 R1 \n \u251c\u2500\u2500 R2 \n \u2514\u2500\u2500 R3 \n<\/code><\/pre>\n<p>\u06cc\u06c1 \u0635\u0631\u0641 R1 \u06a9\u0648 \u0645\u0633\u062a\u0631\u062f \u06a9\u0631\u0646\u06d2 \u0633\u06d2 \u06a9\u06c1\u06cc\u06ba \u0632\u06cc\u0627\u062f\u06c1 \u0637\u0627\u0642\u062a\u0648\u0631 \u06c1\u06d2\u06d4<\/p>\n<h2 id=\"heading-18-why-we-have-sessions\">18. \u0633\u06cc\u0634\u0646 \u06a9\u06cc\u0648\u06ba\u061f<\/h2>\n<p>\u06c1\u0645\u0627\u0631\u0627 \u0633\u0633\u0679\u0645 \u0641\u06cc \u0635\u0627\u0631\u0641 \u0635\u0631\u0641 \u0627\u06cc\u06a9 JWT \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u060c \u062a\u0648 \u067e\u06be\u0631 \u06c1\u0645\u0627\u0631\u06d2 \u067e\u0627\u0633 \u0633\u06cc\u0634\u0646 \u06a9\u06cc\u0648\u06ba \u06c1\u0648\u062a\u06d2 \u06c1\u06cc\u06ba\u061f<\/p>\n<p>\u0633\u06cc\u0634\u0646 \u06a9\u06d2 \u0628\u063a\u06cc\u0631\u060c \u0633\u0633\u0679\u0645 \u0645\u06cc\u06ba \u0635\u0631\u0641 \u0635\u0627\u0631\u0641 \u0627\u0648\u0631 \u0679\u0648\u06a9\u0646 \u06c1\u0648\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-text\">User\n \u2193\nJWT\n<\/code><\/pre>\n<p>\u0633\u0631\u0648\u0631 \u062c\u0627\u0646\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u0679\u0648\u06a9\u0646 \u06a9\u0633 \u06a9\u0627 \u06c1\u06d2\u060c \u0644\u06cc\u06a9\u0646 \u0627\u0633 \u06a9\u06d2 \u067e\u0627\u0633 \u0679\u0648\u06a9\u0646 \u06a9\u0627 \u06a9\u0648\u0626\u06cc \u062a\u0635\u0648\u0631 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 <em>\u06a9\u06c1\u0627\u06ba<\/em> \u0635\u0627\u0631\u0641 \u0644\u0627\u06af \u0627\u0646 \u06c1\u06d2\u06d4 \u0635\u0627\u0631\u0641 \u06a9\u06d2 \u062a\u0645\u0627\u0645 \u0679\u0648\u06a9\u0646 \u0627\u06cc\u06a9 \u062c\u06cc\u0633\u06d2 \u0646\u0638\u0631 \u0622\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0627\u0633 \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u0633\u0631\u0648\u0631 \u0641\u0648\u0646 \u0644\u0627\u06af \u0627\u0646 \u0627\u0648\u0631 \u0644\u06cc\u067e \u0679\u0627\u067e \u0644\u0627\u06af \u0627\u0646 \u06a9\u06d2 \u062f\u0631\u0645\u06cc\u0627\u0646 \u0641\u0631\u0642 \u0646\u06c1\u06cc\u06ba \u06a9\u0631 \u0633\u06a9\u062a\u0627\u060c \u0627\u0646 \u0645\u06cc\u06ba \u0633\u06d2 \u0635\u0631\u0641 \u0627\u06cc\u06a9 \u06a9\u0648 \u062e\u062a\u0645 \u0646\u06c1\u06cc\u06ba \u06a9\u0631 \u0633\u06a9\u062a\u0627\u060c \u0635\u0627\u0631\u0641 \u06a9\u0648 \u0644\u0627\u06af \u0627\u0646 \u0622\u0644\u0627\u062a \u06a9\u06cc \u0641\u06c1\u0631\u0633\u062a \u0646\u06c1\u06cc\u06ba \u062f\u06a9\u06be\u0627 \u0633\u06a9\u062a\u0627\u060c \u0627\u0648\u0631 \u06cc\u06c1 \u0646\u06c1\u06cc\u06ba \u062c\u0627\u0646 \u0633\u06a9\u062a\u0627 \u06a9\u06c1 \u06a9\u0633 \u0644\u0627\u06af \u0627\u0646 \u06a9\u06cc \u0648\u062c\u06c1 \u0633\u06d2 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u06cc \u0645\u0634\u06a9\u0648\u06a9 \u06a9\u0648\u0634\u0634 \u06c1\u0648\u0626\u06cc\u06d4<\/p>\n<p>\u0648\u0627\u062d\u062f \u0633\u062e\u062a \u0622\u067e\u0634\u0646 \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u0627\u0633 \u0635\u0627\u0631\u0641 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06c1\u0631 \u0686\u06cc\u0632 \u06a9\u0648 \u0628\u0627\u0637\u0644 \u06a9\u0631 \u062f\u06cc\u0627 \u062c\u0627\u0626\u06d2\u060c \u0645\u062b\u0627\u0644 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u062f\u0633\u062a\u062e\u0637 \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u06cc \u06a9\u0644\u06cc\u062f \u06cc\u0627 \u0635\u0627\u0631\u0641 \u06a9\u06d2 \u0679\u0648\u06a9\u0646 \u0648\u0631\u0698\u0646 \u06a9\u0648 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631 \u06a9\u06d2\u06d4<\/p>\n<p>\u0633\u06cc\u0634\u0646\u0632 \u06a9\u06d2 \u0633\u0627\u062a\u06be\u060c \u06c1\u0631 \u0644\u0627\u06af \u0627\u0646 \u06a9\u0627 \u0627\u067e\u0646\u0627 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u0628\u0646 \u062c\u0627\u062a\u0627 \u06c1\u06d2 \u062c\u0633 \u0633\u06d2 \u0679\u0648\u06a9\u0646 \u06a9\u0627 \u062a\u0639\u0644\u0642 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-text\">User\n \u251c\u2500\u2500 Chrome\n \u2502     \u2514\u2500\u2500 Session A\n \u2502\n \u251c\u2500\u2500 Android\n \u2502     \u2514\u2500\u2500 Session B\n \u2502\n \u2514\u2500\u2500 Firefox\n       \u2514\u2500\u2500 Session C\n<\/code><\/pre>\n<p>\u0627\u0628 \u062a\u0645\u0627\u0645 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646\u0632 \u0627\u0648\u0631 \u0627\u06cc\u06a9\u0633\u06cc\u0633 \u0679\u0648\u06a9\u0646 \u0627\u06cc\u06a9 \u0633\u06cc\u0634\u0646 \u0633\u06d2 \u0645\u0646\u0633\u0644\u06a9 \u06c1\u06cc\u06ba \u0628\u0630\u0631\u06cc\u0639\u06c1: <code>sessionId<\/code> \/ <code>sid<\/code>\u0633\u0631\u0648\u0631 \u062f\u0648\u0633\u0631\u06d2 \u0633\u06cc\u0634\u0646 \u06a9\u0648 \u0686\u06be\u0648\u0626\u06d2 \u0628\u063a\u06cc\u0631 \u0627\u06cc\u06a9 \u0633\u06cc\u0634\u0646 \u067e\u0631 \u0622\u067e\u0631\u06cc\u0634\u0646 \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 \u0645\u062b\u0627\u0644 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631\u060c \u0622\u067e \u0644\u0627\u06af\u0648 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-text\">Logout current device\nLogout all devices\nView active sessions\nRevoke one device\nDetect suspicious activity\n<\/code><\/pre>\n<p>\u0627\u06af\u0631 \u06a9\u0648\u0626\u06cc \u0622\u067e \u06a9\u06d2 \u0627\u06cc\u0646\u0688\u0631\u0627\u0626\u06cc\u0688 \u0641\u0648\u0646 \u0633\u06d2 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0686\u0648\u0631\u06cc \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u062a\u0648 \u0633\u06cc\u0634\u0646 B \u0645\u0646\u0633\u0648\u062e \u06a9\u0631 \u062f\u06cc\u0627 \u062c\u0627\u0626\u06d2 \u06af\u0627 \u0627\u0648\u0631 \u0622\u067e \u06a9\u0627 \u0644\u06cc\u067e \u0679\u0627\u067e \u0627\u0648\u0631 \u0641\u0627\u0626\u0631 \u0641\u0627\u06a9\u0633 \u0644\u0627\u06af \u0627\u0646 \u0631\u06c1\u06d2 \u06af\u0627\u06d4 \u0633\u06cc\u0634\u0646 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062f\u06c1 \u0688\u06cc\u0648\u0627\u0626\u0633 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u062e\u0635\u0648\u0635 \u06a9\u0646\u0679\u0631\u0648\u0644 \u06a9\u06cc \u0635\u0644\u0627\u062d\u06cc\u062a\u06cc\u06ba\u06d4<\/p>\n<h2 id=\"heading-19-jwt-authentication-in-nestjs\">19. NestJS \u0645\u06cc\u06ba JWT \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642<\/h2>\n<p>\u0633\u0631\u0648\u0631 \u067e\u0631 <code>Authorization: Bearer <token\/><\/code> \u06c1\u0631 \u0645\u062d\u0641\u0648\u0638 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06d2 \u0644\u06cc\u06d2\u060c \u06c1\u06cc\u0688\u0631 \u0645\u0639\u0631\u0648\u0641 \u0635\u0627\u0631\u0641\u06cc\u0646 \u06a9\u0648 \u0628\u06be\u06cc\u062c\u06d2 \u062c\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 NestJS JWT \u062d\u06a9\u0645\u062a \u0639\u0645\u0644\u06cc \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 \u067e\u0627\u0633\u067e\u0648\u0631\u0679 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0627\u0633\u06d2 \u067e\u0648\u0631\u0627 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u062c\u0648 \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u067e\u0691\u06be\u0646\u06d2 \u0627\u0648\u0631 \u0627\u0633 \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0631\u0646\u06d2 \u06a9\u0627 \u0637\u0631\u06cc\u0642\u06c1 \u0628\u062a\u0627\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u06c1\u0645 \u0622\u067e \u06a9\u0627 \u067e\u0627\u0633\u067e\u0648\u0631\u0679 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u06cc\u06ba \u06af\u06d2:<\/p>\n<pre><code class=\"language-ts\">@Injectable()\nexport class JwtStrategy\n  extends PassportStrategy(\n    Strategy,\n    'jwt',\n  ) {\n\n  constructor(\n    private readonly configService:\n      ConfigService,\n    private readonly usersService:\n      UsersService,\n  ) {\n    super({\n      jwtFromRequest:\n        ExtractJwt\n          .fromAuthHeaderAsBearerToken(),\n\n      ignoreExpiration: false,\n\n      secretOrKey:\n        configService.getOrThrow<string>(\n          'JWT_ACCESS_SECRET',\n        ),\n\n      algorithms: ['HS256'],\n    });\n  }\n\n  async validate(payload: {\n    sub: string;\n    sid: string;\n    type: string;\n  }) {\n\n    if (payload.type !== 'access') {\n      throw new UnauthorizedException();\n    }\n\n    const user =\n      await this.usersService.findById(\n        payload.sub,\n      );\n\n    if (!user) {\n      throw new UnauthorizedException();\n    }\n\n    return {\n      userId: user._id.toString(),\n      sessionId: payload.sid,\n      role: user.role,\n      email: user.email,\n    };\n  }\n}\n<\/string><\/code><\/pre>\n<p>\u06cc\u06c1\u0627\u06ba \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u0627\u0633 \u06a9\u0648\u0688 \u0645\u06cc\u06ba \u062a\u0635\u062f\u06cc\u0642 \u06a9\u06cc\u0633\u06d2 \u06a9\u0627\u0645 \u06a9\u0631\u062a\u06cc \u06c1\u06d2: \u0627\u0633 \u06a9\u06d2 \u062f\u0648 \u0645\u0631\u0627\u062d\u0644 \u06c1\u06cc\u06ba:<\/p>\n<ol>\n<li>\u0633\u0628 \u0633\u06d2 \u067e\u06c1\u0644\u06d2\u060c \u06a9\u0646\u0633\u0679\u0631\u06a9\u0679\u0631 \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0648 \u062a\u0631\u062a\u06cc\u0628 \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4 <code>jwtFromRequest<\/code> \u0627\u0633 \u0646\u06d2 \u0645\u062c\u06be\u06d2 \u0679\u0648\u06a9\u0646 \u0644\u0627\u0646\u06d2 \u06a9\u0648 \u06a9\u06c1\u0627\u06d4 <code>Authorization: Bearer ...<\/code> \u06c1\u06cc\u0688\u0631 <code>ignoreExpiration: false<\/code> \u0627\u0633 \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 \u06a9\u06c1 \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u0679\u0648\u06a9\u0646 \u0645\u0633\u062a\u0631\u062f \u06a9\u0631 \u062f\u06cc\u06d2 \u062c\u0627\u0626\u06cc\u06ba \u06af\u06d2\u06d4 <code>secretOrKey<\/code> \u0686\u06be\u06cc\u0691 \u0686\u06be\u0627\u0691 \u06a9\u0627 \u0679\u0648\u06a9\u0646 \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648 \u062c\u0627\u0626\u06d2 \u06af\u0627 \u06a9\u06cc\u0648\u0646\u06a9\u06c1 \u06cc\u06c1 \u062f\u0633\u062a\u062e\u0637 \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06c1\u0648\u0646\u06d2 \u0648\u0627\u0644\u0627 \u0631\u0627\u0632 \u06c1\u06d2\u06d4 <code>algorithms: ['HS256']<\/code> \u0679\u0648\u06a9\u0646 \u06a9\u06d2 \u062f\u0639\u0648\u0648\u06ba \u067e\u0631 \u0628\u06be\u0631\u0648\u0633\u06c1 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2\u060c \u06cc\u06c1 \u0627\u062c\u0627\u0632\u062a \u0634\u062f\u06c1 \u062f\u0633\u062a\u062e\u0637\u06cc \u0627\u0644\u06af\u0648\u0631\u062a\u06be\u0645 \u06a9\u0648 \u0645\u062d\u062f\u0648\u062f \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u067e\u0627\u0633\u067e\u0648\u0631\u0679 \u0627\u067e\u0646\u06d2 \u06a9\u0648\u0688 \u067e\u0631 \u0639\u0645\u0644 \u062f\u0631\u0622\u0645\u062f \u0633\u06d2 \u067e\u06c1\u0644\u06d2 \u06cc\u06c1 \u062a\u0645\u0627\u0645 \u0686\u06cc\u06a9 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/li>\n<li>\u062f\u0648\u0633\u0631\u0627 <code>validate()<\/code> \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642 \u06a9\u06d2 \u0628\u0639\u062f \u06c1\u06cc \u0639\u0645\u0644 \u0645\u06cc\u06ba \u0644\u0627\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u067e\u06c1\u0644\u06d2 \u062f\u0631\u062c \u0630\u06cc\u0644 \u06a9\u0648 \u0686\u06cc\u06a9 \u06a9\u0631\u06cc\u06ba: <code>type<\/code> \u062f\u0639\u0648\u06cc\u0670 \u06c1\u06d2\u06d4 <code>'access'<\/code> \u0627\u0633 \u0644\u06cc\u06d2\u060c \u062f\u0648\u0633\u0631\u06cc \u0642\u0633\u0645 \u06a9\u06d2 \u0679\u0648\u06a9\u0646 \u06cc\u06c1\u0627\u06ba \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u0646\u06c1\u06cc\u06ba \u06a9\u06cc\u06d2 \u062c\u0627 \u0633\u06a9\u062a\u06d2\u06d4 \u067e\u06be\u0631 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 MongoDB \u0633\u06d2 \u0635\u0627\u0631\u0641 \u06a9\u0648 \u0644\u0648\u0688 \u06a9\u0631\u06cc\u06ba: <code>sub<\/code> \u0627\u06af\u0631 \u0622\u067e \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba \u0627\u0648\u0631 \u0635\u0627\u0631\u0641 \u0627\u0628 \u0645\u0648\u062c\u0648\u062f \u0646\u06c1\u06cc\u06ba \u06c1\u06d2 \u062a\u0648 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0645\u0633\u062a\u0631\u062f \u06a9\u0631\u062f\u06cc \u062c\u0627\u062a\u06cc \u06c1\u06d2\u06d4 \u0622\u062e\u0631 \u0645\u06cc\u06ba\u060c \u0627\u06cc\u06a9 \u0686\u06be\u0648\u0679\u06cc \u0686\u06cc\u0632 (<code>userId<\/code>, <code>sessionId<\/code>, <code>role<\/code>\u06cc\u0627 <code>email<\/code>)\u06d4 \u062c\u0648 \u0628\u06be\u06cc <code>validate()<\/code> \u0631\u06cc\u0679\u0631\u0646 \u0645\u0646\u062f\u0631\u062c\u06c1 \u0630\u06cc\u0644 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0645\u0646\u0633\u0644\u06a9 \u06c1\u06cc\u06ba: <code>req.user<\/code>\u0628\u0639\u062f \u0645\u06cc\u06ba \u0627\u0633\u06d2 \u06af\u0627\u0631\u0688\u0632 \u0627\u0648\u0631 \u06a9\u0646\u0679\u0631\u0648\u0644\u0631\u0632 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/li>\n<\/ol>\n<p>\u0686\u0648\u0646\u06a9\u06c1 \u06a9\u0631\u062f\u0627\u0631 \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u0633\u06d2 \u0622\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0679\u0648\u06a9\u0646 \u0633\u06d2 \u0646\u06c1\u06cc\u06ba\u060c \u0627\u0633 \u0644\u06cc\u06d2 \u0631\u0648\u0644 \u06a9\u06cc \u062a\u0628\u062f\u06cc\u0644\u06cc\u0627\u06ba \u0627\u06af\u0644\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u067e\u0631 \u0627\u062b\u0631 \u0627\u0646\u062f\u0627\u0632 \u06c1\u0648\u062a\u06cc \u06c1\u06cc\u06ba\u06d4 \u0627\u0633 \u0648\u0631\u0698\u0646 \u0645\u06cc\u06ba \u0627\u0628 \u0628\u06be\u06cc \u0627\u06cc\u06a9 \u0633\u06cc\u0634\u0646 \u0628\u0627\u0642\u06cc \u06c1\u06d2 (<code>sid<\/code>) \u0627\u0628 \u0628\u06be\u06cc \u0641\u0639\u0627\u0644 \u06c1\u06d2\u06d4 \u062c\u06cc\u0633\u0627 \u06a9\u06c1 \u067e\u06c1\u0644\u06d2 \u0630\u06a9\u0631 \u06a9\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2\u060c \u0627\u06af\u0631 \u0622\u067e \u06a9\u0648 \u0641\u0648\u0631\u06cc \u0637\u0648\u0631 \u067e\u0631 \u0645\u0646\u0633\u0648\u062e\u06cc \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2\u060c \u062a\u0648 \u0648\u06c1 \u062a\u0635\u062f\u06cc\u0642 \u0634\u0627\u0645\u0644 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<h3 id=\"heading-jwtauthguard\">JwtAuthGuard<\/h3>\n<p>\u0633\u0628 \u0633\u06d2 \u067e\u06c1\u0644\u06d2\u060c \u06af\u0627\u0631\u0688 \u06a9\u06cc\u0627 \u06c1\u06d2\u061f \u06af\u0627\u0631\u0688 \u06a9\u0648\u0688 \u06a9\u0627 \u0627\u06cc\u06a9 \u0679\u06a9\u0691\u0627 \u06c1\u06d2 \u062c\u0648 \u0627\u0633 \u0628\u0627\u062a \u06a9\u0627 \u062a\u0639\u06cc\u0646 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u0622\u06cc\u0627 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u062c\u0627\u0631\u06cc \u0631\u06c1 \u0633\u06a9\u062a\u06cc \u06c1\u06d2\u06d4 \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u06cc\u06c1 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 <em>\u067e\u06c1\u0644\u06d2<\/em> \u0627\u0635\u0644\u06cc \u0631\u0627\u0633\u062a\u06c1 \u06c1\u06cc\u0646\u0688\u0644\u0631\u06d4 \u0627\u06af\u0631 \u06af\u0627\u0631\u0688 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u060c \u062a\u0648 \u06c1\u06cc\u0646\u0688\u0644\u0631 \u06a9\u0648 \u067e\u06be\u0627\u0646\u0633\u06cc \u062f\u06d2 \u062f\u06cc \u062c\u0627\u062a\u06cc \u06c1\u06d2\u06d4 \u0645\u0633\u062f\u0648\u062f \u06a9\u0631\u0646\u0627 \u06c1\u06cc\u0646\u0688\u0644\u0631 \u06a9\u0648 \u0686\u0644\u0646\u06d2 \u0633\u06d2 \u0631\u0648\u06a9\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u06cc\u06c1 \u0627\u0635\u0637\u0644\u0627\u062d \u062f\u0648\u0646\u0648\u06ba \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u0645\u06cc\u06ba \u0627\u06cc\u06a9 \u06c1\u06cc \u062a\u0635\u0648\u0631 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0638\u0627\u06c1\u0631 \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<ul>\n<li>\u0646\u06c1\u06cc\u06ba <strong>\u0632\u0627\u0648\u06cc\u06c1 \u06af\u0627\u0631\u0688<\/strong> \u0646\u06cc\u0648\u06cc\u06af\u06cc\u0634\u0646 \u06a9\u06d2 \u062f\u0648\u0631\u0627\u0646 \u0628\u0631\u0627\u0624\u0632\u0631 \u0645\u06cc\u06ba \u0686\u0644\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0627\u0633 \u0628\u0627\u062a \u06a9\u0627 \u062a\u0639\u06cc\u0646 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u0622\u06cc\u0627 \u0631\u0648\u0679\u0631 \u0635\u0641\u062d\u06c1 \u06a9\u06be\u0648\u0644 \u0633\u06a9\u062a\u0627 \u06c1\u06d2 (\u0645\u062b\u0627\u0644 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631\u060c \u0627\u06af\u0631 \u0635\u0627\u0631\u0641 \u0644\u0627\u06af \u0627\u0646 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2 \u062a\u0648 \u0644\u0627\u06af \u0627\u0646 \u0635\u0641\u062d\u06c1 \u067e\u0631 \u0631\u06cc \u0688\u0627\u0626\u0631\u06cc\u06a9\u0679)\u06d4 \u06cc\u06c1 UX \u06a9\u06cc \u062e\u0635\u0648\u0635\u06cc\u062a \u06c1\u06d2\u06d4<\/li>\n<li>\u06a9\u0648\u0626\u06cc \u0631\u0627\u0633\u062a\u06c1 \u0646\u06c1\u06cc\u06ba <strong>NestJS \u06af\u0627\u0631\u0688<\/strong> \u06cc\u06c1 \u0627\u0633 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0627\u06cc\u06a9 \u06a9\u0644\u0627\u0633 \u06c1\u06d2\u06d4 <code>canActivate()<\/code> \u06a9\u0646\u0679\u0631\u0648\u0644\u0631 \u0637\u0631\u06cc\u0642\u0648\u06ba \u0633\u06d2 \u067e\u06c1\u0644\u06d2 \u0633\u0631\u0648\u0631 \u067e\u0631 \u0686\u0644\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u0637\u0631\u06cc\u0642\u06d2\u06d4 \u0627\u0633 \u0628\u0627\u062a \u06a9\u0627 \u062a\u0639\u06cc\u0646 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u0622\u06cc\u0627 HTTP \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u0627\u062e\u062a\u062a\u0627\u0645\u06cc \u0646\u0642\u0637\u06c1 \u062a\u06a9 \u067e\u06c1\u0646\u0686 \u0633\u06a9\u062a\u06cc \u06c1\u06cc\u06ba\u06d4 \u06cc\u06c1 \u0648\u06c1\u06cc \u06c1\u06d2 \u062c\u0648 \u062d\u0642\u06cc\u0642\u06cc \u0633\u06cc\u06a9\u0648\u0631\u0679\u06cc \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2.<\/li>\n<\/ul>\n<p><code>JwtAuthGuard<\/code>    NestJS \u06af\u0627\u0631\u0688\u06d4 \u067e\u0627\u0633\u067e\u0648\u0631\u0679 \u06a9\u06cc \u0628\u0646\u06cc\u0627\u062f \u067e\u0631 \u0628\u0646\u0627\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2\u06d4 <code>AuthGuard('jwt')<\/code>\u06a9\u06c1\u0627\u06ba <code>'jwt'<\/code> \u062c\u0648 \u0646\u0627\u0645 \u06c1\u0645 \u0646\u06d2 \u062f\u06cc\u0627 \u06c1\u06d2\u06d4 <code>JwtStrategy<\/code>. \u062c\u0628 \u06a9\u0648\u0626\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0622\u062a\u06cc \u06c1\u06d2 \u062a\u0648 \u06af\u0627\u0631\u0688 \u0627\u067e\u0646\u06cc \u062d\u06a9\u0645\u062a \u0639\u0645\u0644\u06cc \u067e\u0631 \u0639\u0645\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u06cc\u0639\u0646\u06cc \u0679\u0648\u06a9\u0646 \u0646\u06a9\u0627\u0644\u06cc\u06ba \u0627\u0648\u0631 \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0631\u06cc\u06ba \u0627\u0648\u0631 <code>validate()<\/code>\u0627\u0648\u0631 \u0627\u06af\u0631 \u0633\u0628 \u06a9\u0686\u06be \u0679\u06be\u06cc\u06a9 \u0631\u06c1\u0627 \u062a\u0648 \u06c1\u0645 \u0646\u062a\u0627\u0626\u062c \u0638\u0627\u06c1\u0631 \u06a9\u0631\u06cc\u06ba \u06af\u06d2\u06d4 <code>req.user<\/code> \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06af\u0632\u0631\u0646\u06d2 \u062f\u06cc\u06ba\u06d4 \u0627\u06af\u0631 \u06a9\u0686\u06be \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648\u062c\u0627\u062a\u0627 \u06c1\u06d2\u060c \u062a\u0648 \u06cc\u06c1 \u0627\u0633 \u0637\u0631\u062d \u062c\u0648\u0627\u0628 \u062f\u06cc\u062a\u0627 \u06c1\u06d2: <code>401 Unauthorized<\/code>\u06a9\u0646\u0679\u0631\u0648\u0644\u0631 \u0646\u06c1\u06cc\u06ba \u0686\u0644 \u0631\u06c1\u0627 \u06c1\u06d2\u06d4 \u0635\u0648\u0627\u0628\u062f\u06cc\u062f\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0648\u0627\u0644\u06d2 \u0641\u06cc\u0644\u0688\u0632 \u0645\u06cc\u06ba \u0628\u06be\u06cc\u062c\u06cc \u06af\u0626\u06cc \u0627\u0642\u062f\u0627\u0631 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2 \u062a\u0635\u062f\u06cc\u0642 \u0634\u062f\u06c1 \u0633\u0631\u0648\u0631 \u0633\u0627\u0626\u06cc\u0688 \u062f\u0639\u0648\u0648\u06ba \u067e\u0631 \u0627\u0646\u062d\u0635\u0627\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-ts\">@Injectable()\nexport class JwtAuthGuard\n  extends AuthGuard('jwt') {}\n<\/code><\/pre>\n<p>\u0627\u0628:<\/p>\n<pre><code class=\"language-ts\">@Get('me')\n@UseGuards(JwtAuthGuard)\nme(@Req() req: Request) {\n  return req.user;\n}\n<\/code><\/pre>\n<p>\u06cc\u06c1\u0627\u06ba\u060c <code>@UseGuards(JwtAuthGuard)<\/code> \u06af\u0627\u0631\u0688 \u06a9\u0648 \u0645\u0646\u0633\u0644\u06a9 \u06a9\u0631\u06cc\u06ba\u06d4 <code>me<\/code> \u0627\u062e\u062a\u062a\u0627\u0645\u06cc \u0646\u0642\u0637\u06c1 \u0635\u0631\u0641 \u062f\u0631\u0633\u062a \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u0648\u0627\u0644\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u06af\u0632\u0631\u06cc\u06ba \u06af\u06cc \u0627\u0648\u0631 \u06c1\u06cc\u0646\u0688\u0644\u0631 \u062a\u0635\u062f\u06cc\u0642 \u0634\u062f\u06c1 \u0635\u0627\u0631\u0641 \u06a9\u0648 \u0630\u062e\u06cc\u0631\u06c1 \u0634\u062f\u06c1 \u062d\u06a9\u0645\u062a \u0639\u0645\u0644\u06cc \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0648\u0627\u067e\u0633 \u06a9\u0631 \u062f\u06d2 \u06af\u0627\u06d4 <code>req.user<\/code>.<\/p>\n<p>\u067e\u0633\u062f\u06cc\u062f \u0627\u06cc\u06a9 \u062d\u0642\u06cc\u0642\u06cc \u062d\u0641\u0627\u0638\u062a\u06cc \u062f\u0627\u0626\u0631\u06c1 \u0628\u0646 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u06a9\u0648\u0646\u06cc\u06cc \u06af\u0627\u0631\u0688\u0632 \u0635\u0631\u0641 \u0646\u06cc\u0648\u06cc\u06af\u06cc\u0634\u0646 UX \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06c1\u0648\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<h3 id=\"heading-angular-guard-isnt-security\">\u06a9\u0648\u0646\u06cc\u06cc \u06af\u0627\u0631\u0688 \u0633\u06cc\u06a9\u0648\u0631\u0679\u06cc \u0646\u06c1\u06cc\u06ba \u06c1\u06d2<\/h3>\n<p>\u0627\u0646\u06af\u0648\u0644\u0631 \u06af\u0627\u0631\u0688 \u0646\u06cc\u0648\u06cc\u06af\u06cc\u0634\u0646 \u0627\u0648\u0631 \u0635\u0627\u0631\u0641 \u06a9\u06d2 \u062a\u062c\u0631\u0628\u06d2 \u06a9\u0648 \u0628\u06c1\u062a\u0631 \u0628\u0646\u0627\u062a\u0627 \u06c1\u06d2\u060c \u0644\u06cc\u06a9\u0646 \u0635\u0627\u0631\u0641\u06cc\u0646 \u06a9\u0648 \u0628\u0631\u0627\u0624\u0632\u0631 \u06a9\u0648\u0688 \u06a9\u0648 \u0646\u0638\u0631\u0627\u0646\u062f\u0627\u0632 \u06a9\u0631\u0646\u06d2 \u0627\u0648\u0631 APIs \u06a9\u0648 \u0628\u0631\u0627\u06c1 \u0631\u0627\u0633\u062a \u06a9\u0627\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4 \u0644\u06c1\u0630\u0627\u060c NestJS \u0645\u06cc\u06ba \u0628\u06be\u06cc \u062a\u0635\u062f\u06cc\u0642 \u0627\u0648\u0631 \u0627\u062c\u0627\u0632\u062a \u06a9\u06d2 \u062a\u0645\u0627\u0645 \u0627\u0635\u0648\u0644 \u0644\u0627\u06af\u0648 \u06c1\u0648\u0646\u06d2 \u0686\u0627\u06c1\u0626\u06cc\u06ba\u06d4<\/p>\n<p>\u06cc\u06c1 \u0627\u06cc\u06a9 \u0628\u06c1\u062a \u0627\u06c1\u0645 \u0627\u0635\u0648\u0644 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-text\">Angular Guard\n      \u2193\nUX \/ Navigation\n\nNestJS Guard\n      \u2193\nSecurity\n<\/code><\/pre>\n<p>\u062d\u0645\u0644\u06c1 \u0622\u0648\u0631 \u0627\u0646\u06af\u0648\u0644\u0631 \u06a9\u0648 \u0645\u06a9\u0645\u0644 \u0637\u0648\u0631 \u067e\u0631 \u0646\u0638\u0631\u0627\u0646\u062f\u0627\u0632 \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 \u0645\u062b\u0627\u0644 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631\u060c \u0622\u067e \u0679\u0648\u0644\u0632 \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 \u06a9\u0645\u0627\u0646\u0688 \u0644\u0627\u0626\u0646 \u0633\u06d2 \u0628\u0631\u0627\u06c1 \u0631\u0627\u0633\u062a \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u0628\u06be\u06cc\u062c \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba \u062c\u06cc\u0633\u06d2: <code>curl<\/code>:<\/p>\n<pre><code class=\"language-bash\">curl ...\n<\/code><\/pre>\n<p>\u06cc\u0627\u060c \u06a9\u0648\u0626\u06cc \u062f\u0648\u0633\u0631\u0627 \u0679\u0648\u0644 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u06cc\u06ba \u062c\u0648 \u0641\u0631\u0646\u0679 \u0627\u06cc\u0646\u0688 \u06a9\u0648 \u0686\u0644\u0627\u0626\u06d2 \u0628\u063a\u06cc\u0631 \u062e\u0627\u0645 HTTP \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u0628\u06be\u06cc\u062c\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-text\">Postman\nBurp Suite\ncustom script\n<\/code><\/pre>\n<p>\u067e\u0648\u0633\u0679 \u0645\u06cc\u0646 \u0627\u06cc\u06a9 API \u06a9\u0644\u0627\u0626\u0646\u0679 \u06c1\u06d2\u060c Burp Suite \u0627\u06cc\u06a9 \u0633\u06cc\u06a9\u0648\u0631\u0679\u06cc \u0679\u06cc\u0633\u0679\u0646\u06af \u067e\u0631\u0627\u06a9\u0633\u06cc \u06c1\u06d2 \u062c\u0648 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u0648 \u06af\u0631\u0641\u062a \u0627\u0648\u0631 \u0627\u0633 \u0645\u06cc\u06ba \u062a\u0631\u0645\u06cc\u0645 \u06a9\u0631 \u0633\u06a9\u062a\u06cc \u06c1\u06d2\u060c \u0627\u0648\u0631 \u0627\u06cc\u06a9 \u062d\u0633\u0628 \u0636\u0631\u0648\u0631\u062a \u0627\u0633\u06a9\u0631\u067e\u0679 \u06a9\u0648\u0626\u06cc \u0628\u06be\u06cc \u067e\u0631\u0648\u06af\u0631\u0627\u0645 \u06c1\u06d2 \u062c\u0648 \u0628\u0631\u0627\u06c1 \u0631\u0627\u0633\u062a API \u06a9\u06d2 URL \u06a9\u0648 \u06a9\u0627\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0646 \u0645\u06cc\u06ba \u0633\u06d2 \u06a9\u0648\u0626\u06cc \u0628\u06be\u06cc \u0627\u0646\u06af\u0648\u0644\u0631 \u06a9\u0648\u0688 \u067e\u0631 \u0639\u0645\u0644 \u062f\u0631\u0622\u0645\u062f \u0646\u06c1\u06cc\u06ba \u06a9\u0631 \u0631\u06c1\u0627 \u06c1\u06d2\u060c \u0644\u06c1\u0630\u0627 \u0627\u0646\u06c1\u06cc\u06ba \u0627\u0646\u06af\u0648\u0644\u0631 \u06af\u0627\u0631\u0688\u0632 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u0646\u06c1\u06cc\u06ba \u0631\u0648\u06a9\u0627 \u062c\u0627\u0626\u06d2 \u06af\u0627\u06d4<\/p>\n<p>\u0627\u0633 \u0644\u06cc\u06d2\u060c \u062a\u0645\u0627\u0645 \u062d\u0633\u0627\u0633 \u0627\u06cc\u0646\u0688 \u067e\u0648\u0627\u0626\u0646\u0679\u0633 \u06a9\u0648 \u067e\u0633\u062f\u06cc\u062f \u067e\u0631 \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0648 \u0646\u0627\u0641\u0630 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<h2 id=\"heading-20-rbac\">20. \u0622\u0631 \u0628\u06cc \u0627\u06d2 \u0633\u06cc<\/h2>\n<p>\u0633\u0631\u0679\u06cc\u0641\u06cc\u06a9\u06cc\u0634\u0646 \u06c1\u0645\u06cc\u06ba \u0628\u062a\u0627\u062a\u0627 \u06c1\u06d2 <em>\u0688\u0628\u0644\u06cc\u0648 \u0627\u06cc\u0686 \u0627\u0648<\/em> \u0635\u0627\u0631\u0641\u06d4 \u0627\u06af\u0644\u0627 \u06c1\u0645\u06cc\u06ba \u06cc\u06c1 \u0637\u06d2 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2 \u06a9\u06c1 \u0648\u06c1 \u06a9\u06cc\u0627 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0627\u06cc\u0633\u0627 \u06a9\u0631\u0646\u06d2 \u06a9\u0627 \u0627\u06cc\u06a9 \u0639\u0627\u0645 \u0637\u0631\u06cc\u0642\u06c1 \u06a9\u0631\u062f\u0627\u0631\u0648\u06ba \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06c1\u06d2\u06d4<\/p>\n<p>\u0627\u06cc\u06a9 \u06a9\u0631\u062f\u0627\u0631 \u0635\u0627\u0631\u0641 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0645\u0646\u0633\u0644\u06a9 \u0627\u06cc\u06a9 \u0644\u06cc\u0628\u0644 \u06c1\u06d2 \u062c\u0648 \u0631\u0633\u0627\u0626\u06cc \u06a9\u06cc \u0648\u0633\u06cc\u0639 \u0633\u0637\u062d \u06a9\u0648 \u0628\u06cc\u0627\u0646 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u06c1\u0645\u0627\u0631\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u062a\u06cc\u0646 \u0686\u06cc\u0632\u0648\u06ba \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06cc \u06c1\u06d2:<\/p>\n<ul>\n<li><code>USER<\/code>: \u06cc\u06c1 \u0627\u06cc\u06a9 \u0639\u0627\u0645 \u0627\u06a9\u0627\u0624\u0646\u0679 \u06c1\u06d2\u06d4 \u0622\u067e \u0627\u06cc\u067e\u0644\u06cc\u06a9\u06cc\u0634\u0646 \u06a9\u0648 \u0639\u0627\u0645 \u0637\u0648\u0631 \u067e\u0631 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba \u0627\u0648\u0631 \u0627\u067e\u0646\u06d2 \u0688\u06cc\u0679\u0627 \u06a9\u0627 \u062e\u0648\u062f \u0627\u0646\u062a\u0638\u0627\u0645 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/li>\n<li><code>MODERATOR<\/code>: \u0627\u06cc\u06a9 \u0642\u0627\u0628\u0644 \u0627\u0639\u062a\u0645\u0627\u062f \u0627\u06a9\u0627\u0624\u0646\u0679 \u062c\u0633 \u0645\u06cc\u06ba \u0645\u0648\u0627\u062f \u06cc\u0627 \u062f\u0648\u0633\u0631\u06d2 \u0635\u0627\u0631\u0641\u06cc\u0646 \u06a9\u06d2 \u0627\u0639\u0645\u0627\u0644 \u067e\u0631 \u0627\u0636\u0627\u0641\u06cc \u06a9\u0646\u0679\u0631\u0648\u0644 \u06c1\u0648\u060c \u0628\u0634\u0645\u0648\u0644 \u0646\u0627\u0645\u0646\u0627\u0633\u0628 \u067e\u0648\u0633\u0679\u0633 \u06a9\u0648 \u06c1\u0679\u0627\u0646\u0627\u06d4<\/li>\n<li><code>ADMIN<\/code>: \u0627\u06cc\u06a9 \u0645\u06a9\u0645\u0644 \u0628\u06be\u0631\u0648\u0633\u06c1 \u0645\u0646\u062f \u0627\u06a9\u0627\u0624\u0646\u0679 \u062c\u0648 \u0633\u0633\u0679\u0645 \u06a9\u0627 \u0646\u0638\u0645 \u0648 \u0646\u0633\u0642 \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u060c \u0628\u0634\u0645\u0648\u0644 \u0635\u0627\u0631\u0641 \u0627\u06a9\u0627\u0624\u0646\u0679\u0633 \u06a9\u06cc \u0641\u06c1\u0631\u0633\u062a \u0628\u0646\u0627\u0646\u0627\u060c \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u0646\u0627 \u0627\u0648\u0631 \u062d\u0630\u0641 \u06a9\u0631\u0646\u0627\u06d4<\/li>\n<\/ul>\n<p>\u0631\u0648\u0644 \u067e\u0631 \u0645\u0628\u0646\u06cc \u0631\u0633\u0627\u0626\u06cc \u06a9\u0646\u0679\u0631\u0648\u0644 (RBAC) \u0635\u0627\u0631\u0641\u06cc\u0646 \u06a9\u0648 \u06a9\u0631\u062f\u0627\u0631\u0648\u06ba \u0627\u0648\u0631 \u06a9\u0631\u062f\u0627\u0631\u0648\u06ba \u06a9\u06cc \u0648\u0633\u06cc\u0639 \u0631\u06cc\u0646\u062c \u06a9\u06cc \u0635\u0644\u0627\u062d\u06cc\u062a\u0648\u06ba \u06a9\u0627 \u0646\u0642\u0634\u06c1 \u0628\u0646\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u0631\u0648\u0644 \u0627\u0633\u0627\u0626\u0646\u0645\u0646\u0679\u0633 \u06a9\u0648 \u0642\u0627\u0628\u0644 \u0627\u0639\u062a\u0645\u0627\u062f \u0633\u0631\u0648\u0631 \u0633\u0627\u0626\u06cc\u0688 \u06a9\u0646\u0679\u0631\u0648\u0644 \u06a9\u06d2 \u062a\u062d\u062a \u0631\u06a9\u06be\u0627 \u062c\u0627\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u0645\u062b\u0627\u0644 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631\u060c \u0622\u067e \u06a9\u0648 \u0631\u062c\u0633\u0679\u0631\u06cc\u0634\u0646 \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u0648 \u0627\u0646 \u06a9\u06d2 \u0627\u067e\u0646\u06d2 \u06a9\u0631\u062f\u0627\u0631 \u0645\u062a\u0639\u06cc\u0646 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u0646\u06c1\u06cc\u06ba \u062f\u06cc\u0646\u06cc \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<p>\u06c1\u0645\u0627\u0631\u0627 \u06a9\u0631\u062f\u0627\u0631 \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1:<\/p>\n<pre><code class=\"language-ts\">export enum UserRole {\n  USER = 'user',\n  MODERATOR = 'moderator',\n  ADMIN = 'admin',\n}\n<\/code><\/pre>\n<p>\u06a9\u0631\u062f\u0627\u0631 \u0627\u0633 \u0648\u0633\u06cc\u0639 \u0633\u0648\u0627\u0644 \u06a9\u0627 \u062c\u0648\u0627\u0628 \u062f\u06cc\u062a\u06d2 \u06c1\u06cc\u06ba \u06a9\u06c1 \u0635\u0627\u0631\u0641 \u06a9\u06cc\u0627 \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 &quot;\u06a9\u06cc\u0627 \u06cc\u06c1 \u0634\u062e\u0635 \u0627\u06cc\u0688\u0645\u0646 \u0627\u06cc\u0631\u06cc\u0627 \u062a\u06a9 \u0631\u0633\u0627\u0626\u06cc \u062d\u0627\u0635\u0644 \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u061f&#8221; \u06cc\u06c1 \u0648\u0633\u0627\u0626\u0644 \u06a9\u06cc \u0633\u0637\u062d \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u0633\u06d2 \u0645\u062e\u062a\u0644\u0641 \u06c1\u06d2\u060c \u062c\u0648 \u062c\u0648\u0627\u0628 \u062f\u06cc\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u0622\u06cc\u0627 \u06cc\u06c1 \u0635\u0627\u0631\u0641 \u0627\u0633 \u0645\u062e\u0635\u0648\u0635 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u067e\u0631 \u06a9\u0648\u0626\u06cc \u06a9\u0627\u0631\u0631\u0648\u0627\u0626\u06cc \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 &quot;\u06a9\u06cc\u0627 \u06cc\u06c1 \u0634\u062e\u0635 \u06c1\u062c\u06d2 \u0646\u0645\u0628\u0631 123 \u06a9\u0648 \u06a9\u06be\u0648\u0644 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u061f&#8221;<\/p>\n<p>\u062f\u0648\u0646\u0648\u06ba \u0628\u0627\u0642\u0627\u0639\u062f\u06c1 \u0635\u0627\u0631\u0641\u06cc\u0646 <code>USER<\/code> \u0648\u06c1 \u0627\u067e\u0646\u0627 \u06a9\u0631\u062f\u0627\u0631 \u0627\u062f\u0627 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba \u0644\u06cc\u06a9\u0646 \u06a9\u0633\u06cc \u0628\u06be\u06cc \u0641\u0631\u06cc\u0642 \u06a9\u0648 \u062f\u0648\u0633\u0631\u06d2 \u06a9\u0627 \u062d\u06a9\u0645 \u0646\u06c1\u06cc\u06ba \u067e\u0691\u06be\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u0644\u06c1\u0630\u0627\u060c \u06c1\u0631 \u0627\u06cc\u06a9 \u0627\u062e\u062a\u062a\u0627\u0645\u06cc \u0646\u0642\u0637\u06c1 \u06a9\u06d2 \u0644\u06cc\u06d2 \u062c\u0648 \u0627\u06cc\u06a9 \u062e\u0627\u0635 \u0631\u06cc\u06a9\u0627\u0631\u0688 (\u0622\u0631\u0688\u0631\u060c \u067e\u0631\u0648\u0641\u0627\u0626\u0644\u060c \u062f\u0633\u062a\u0627\u0648\u06cc\u0632) \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0633\u0631\u0648\u0633 \u0644\u06cc\u0626\u0631 \u067e\u0631 \u0686\u06cc\u06a9 \u06a9\u0631\u06cc\u06ba \u06a9\u06c1 \u0622\u06cc\u0627 \u0648\u06c1 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u0645\u0648\u062c\u0648\u062f\u06c1 \u0635\u0627\u0631\u0641 \u06a9\u0627 \u06c1\u06d2 \u06cc\u0627 \u0627\u0633 \u06a9\u06d2 \u067e\u0627\u0633 \u0627\u0633 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u06a9\u06cc \u0648\u0627\u0636\u062d \u0627\u062c\u0627\u0632\u062a \u06c1\u06d2\u06d4 \u0627\u0646 \u0627\u062e\u062a\u062a\u0627\u0645\u06cc \u0646\u0642\u0637\u0648\u06ba \u06a9\u06d2 \u0644\u06cc\u06d2 \u0635\u0631\u0641 \u06a9\u0631\u062f\u0627\u0631 \u06c1\u06cc \u06a9\u0627\u0641\u06cc \u0646\u06c1\u06cc\u06ba \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u0627\u06af\u0644\u06d2 \u0686\u0646\u062f \u0630\u06cc\u0644\u06cc \u062d\u0635\u0648\u06ba \u0645\u06cc\u06ba\u060c \u06c1\u0645 \u0631\u0648\u0644 \u0631\u06cc\u0632\u0648\u0644\u0648\u0634\u0646 \u06a9\u0627 \u062d\u0635\u06c1 \u0644\u06a9\u06be\u06cc\u06ba \u06af\u06d2: \u0688\u06cc\u06a9\u0648\u0631\u06cc\u0679\u0631 \u062c\u0648 \u0627\u062e\u062a\u062a\u0627\u0645\u06cc \u0646\u0642\u0637\u06c1 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0636\u0631\u0648\u0631\u06cc \u06a9\u0631\u062f\u0627\u0631\u0648\u06ba \u06a9\u0627 \u0627\u0639\u0644\u0627\u0646 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0648\u06c1 \u0645\u062d\u0627\u0641\u0638 \u062c\u0648 \u0627\u0646 \u06a9\u0648 \u0646\u0627\u0641\u0630 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u0627\u0646 \u06a9\u0648 \u0627\u06cc\u06a9 \u0633\u0627\u062a\u06be \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0627\u06cc\u06a9 \u0645\u062b\u0627\u0644\u06d4<\/p>\n<h3 id=\"heading-roles\">@\u06a9\u0631\u062f\u0627\u0631()<\/h3>\n<p>\u06c1\u0645 \u06a9\u0646\u0679\u0631\u0648\u0644\u0631 \u06a9\u06d2 \u0637\u0631\u06cc\u0642\u06c1 \u06a9\u0627\u0631 \u0633\u06d2 \u06cc\u06c1 \u0628\u062a\u0627\u0646\u06d2 \u06a9\u0627 \u0627\u06cc\u06a9 \u0622\u0633\u0627\u0646 \u0637\u0631\u06cc\u0642\u06c1 \u0686\u0627\u06c1\u062a\u06d2 \u06c1\u06cc\u06ba \u06a9\u06c1 \u06a9\u0648\u0646 \u0633\u06d2 \u06a9\u0631\u062f\u0627\u0631 \u0627\u0633\u06d2 \u06a9\u06c1\u06c1 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 NestJS \u0622\u067e \u06a9\u0648 \u0627\u067e\u0646\u06cc \u0645\u0631\u0636\u06cc \u06a9\u06d2 \u0645\u0637\u0627\u0628\u0642 \u0645\u0639\u0644\u0648\u0645\u0627\u062a (\u062c\u0633\u06d2 \u0645\u06cc\u0679\u0627 \u0688\u06cc\u0679\u0627 \u06a9\u06c1\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2) \u0631\u0648\u0679\u0633 \u0633\u06d2 \u0645\u0646\u0633\u0644\u06a9 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4 <code>SetMetadata<\/code>. \u06a9\u06c1 <code>@Roles()<\/code> \u0627\u06cc\u06a9 \u0688\u06cc\u06a9\u0648\u0631\u06cc\u0679\u0631 \u0627\u0633 \u06a9\u06d2 \u0627\u0631\u062f \u06af\u0631\u062f \u0627\u06cc\u06a9 \u0686\u06be\u0648\u0679\u0627 \u0633\u0627 \u0631\u06cc\u067e\u0631 \u06c1\u06d2. \u06cc\u06c1 \u0631\u0627\u0633\u062a\u06d2 \u0645\u06cc\u06ba \u0627\u062c\u0627\u0632\u062a \u06cc\u0627\u0641\u062a\u06c1 \u06a9\u0631\u062f\u0627\u0631\u0648\u06ba \u06a9\u06cc \u0641\u06c1\u0631\u0633\u062a \u06a9\u0648 \u0627\u0633\u0679\u0648\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u062a\u0627\u06a9\u06c1 \u0627\u06af\u0644\u0627 \u06af\u0627\u0631\u0688 \u062c\u0648 \u0622\u067e \u0644\u06a9\u06be\u06cc\u06ba \u0627\u0633\u06d2 \u067e\u0691\u06be \u0633\u06a9\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-ts\">export const ROLES_KEY = 'roles';\n\nexport const Roles =\n  (...roles: UserRole[]) =>\n    SetMetadata(\n      ROLES_KEY,\n      roles,\n    );\n<\/code><\/pre>\n<p>\u0688\u06cc\u06a9\u0648\u0631\u06cc\u0679\u0631 \u0628\u0630\u0627\u062a \u062e\u0648\u062f \u06a9\u0633\u06cc \u0686\u06cc\u0632 \u06a9\u0648 \u0645\u062c\u0628\u0648\u0631 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u062a\u0627\u06d4 \u0635\u0631\u0641 \u0631\u0627\u0633\u062a\u0648\u06ba \u06a9\u0648 \u0644\u06cc\u0628\u0644 \u06a9\u0631\u06cc\u06ba\u06d4 \u0645\u062b\u0627\u0644 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631:<\/p>\n<pre><code class=\"language-ts\">@Roles(UserRole.ADMIN)\n<\/code><\/pre>\n<p>\u0637\u0631\u06cc\u0642\u06c1:<\/p>\n<pre><code class=\"language-text\">Only ADMIN users\n<\/code><\/pre>\n<p>\u0622\u067e \u0627\u06cc\u06a9 \u0633\u06d2 \u0632\u06cc\u0627\u062f\u06c1 \u06a9\u0631\u062f\u0627\u0631 \u067e\u0627\u0633 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u0633 \u0637\u0631\u062d: <code>@Roles(UserRole.ADMIN, UserRole.MODERATOR)<\/code>\u0627\u0633 \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 \u06a9\u06c1 \u06a9\u0633\u06cc \u0628\u06be\u06cc \u06a9\u0631\u062f\u0627\u0631 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u06c1\u06d2\u06d4<\/p>\n<h3 id=\"heading-rolesguard\">\u0631\u0648\u0644\u0632 \u06af\u0627\u0631\u0688<\/h3>\n<p><code>RolesGuard<\/code>    \u06a9\u0648\u0688 \u06a9\u06cc\u0627 \u0646\u0627\u0641\u0630 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u061f <code>@Roles()<\/code> \u0627\u0639\u0644\u0627\u0646 \u0645\u06cc\u06ba NestJS \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u0648\u06ba\u06d4 <code>Reflector<\/code> \u0631\u0627\u0633\u062a\u06d2 \u0645\u06cc\u06ba \u0645\u062d\u0641\u0648\u0638 \u06a9\u0631\u062f\u06c1 \u06a9\u0631\u062f\u0627\u0631\u0648\u06ba \u06a9\u0648 \u067e\u0691\u06be\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0645\u0648\u062c\u0648\u062f\u06c1 \u0635\u0627\u0631\u0641 \u06a9\u06d2 \u06a9\u0631\u062f\u0627\u0631\u0648\u06ba \u0633\u06d2 \u0627\u0646 \u06a9\u0627 \u0645\u0648\u0627\u0632\u0646\u06c1 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 (<code>request.user<\/code>\u06a9\u0648\u0626\u06cc \u0628\u06be\u06cc <code>JwtAuthGuard<\/code> \u06cc\u06c1 \u067e\u06c1\u0644\u06d2 \u06c1\u06cc \u0628\u06be\u0631\u0627 \u06c1\u0648\u0627 \u06c1\u06d2\u06d4)<\/p>\n<pre><code class=\"language-ts\">@Injectable()\nexport class RolesGuard\n  implements CanActivate {\n\n  constructor(\n    private readonly reflector:\n      Reflector,\n  ) {}\n\n  canActivate(\n    context: ExecutionContext,\n  ): boolean {\n\n    const requiredRoles =\n      this.reflector.getAllAndOverride<\n        UserRole[]\n      >(\n        ROLES_KEY,\n        [\n          context.getHandler(),\n          context.getClass(),\n        ],\n      );\n\n    if (!requiredRoles) {\n      return true;\n    }\n\n    const request =\n      context\n        .switchToHttp()\n        .getRequest();\n\n    const user =\n      request.user;\n\n    if (!user) {\n      throw new UnauthorizedException();\n    }\n\n    if (\n      !requiredRoles.includes(\n        user.role,\n      )\n    ) {\n      throw new ForbiddenException(\n        'Insufficient permissions',\n      );\n    }\n\n    return true;\n  }\n}\n<\/code><\/pre>\n<p>\u0627\u0633 \u06a9\u0648\u0688 \u0645\u06cc\u06ba \u06a9\u06cc\u0627 \u06c1\u0648 \u0631\u06c1\u0627 \u06c1\u06d2\u061f<\/p>\n<ol>\n<li><code>getAllAndOverride<\/code>    \u067e\u0691\u06be\u06cc\u06ba <code>roles<\/code> \u0645\u06cc\u0679\u0627 \u0688\u06cc\u0679\u0627 \u06a9\u0648 \u067e\u06c1\u0644\u06d2 \u0637\u0631\u06cc\u0642\u06c1 \u0633\u06d2 \u0627\u0648\u0631 \u067e\u06be\u0631 \u06a9\u0646\u0679\u0631\u0648\u0644\u0631 \u06a9\u0644\u0627\u0633 \u0633\u06d2 \u06a9\u06be\u06cc\u0646\u0686\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u060c \u0644\u06c1\u0630\u0627 \u0637\u0631\u06cc\u0642\u06c1 \u06a9\u0627\u0631 \u067e\u0631 \u0633\u06cc\u0679 \u0631\u0648\u0644 \u067e\u0648\u0631\u06cc \u06a9\u0644\u0627\u0633 \u067e\u0631 \u0633\u06cc\u0679 \u0631\u0648\u0644 \u06a9\u0648 \u0627\u0648\u0648\u0631 \u0631\u0627\u0626\u06cc\u0688 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/li>\n<li>\u0627\u06af\u0631 \u06a9\u0633\u06cc \u06a9\u0631\u062f\u0627\u0631 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u0646\u06c1\u06cc\u06ba \u06c1\u06d2 (\u06a9\u0648\u0626\u06cc \u0646\u06c1\u06cc\u06ba\u06d4 <code>@Roles()<\/code>)\u060c \u06af\u0627\u0631\u0688 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u067e\u0627\u0633 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/li>\n<li>\u0645\u0648\u062c\u0648\u062f\u06c1 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0627\u0648\u0631 \u0645\u062a\u0639\u0644\u0642\u06c1 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u062d\u0627\u0635\u0644 \u06a9\u0631\u06cc\u06ba\u06d4 <code>user<\/code>. \u0627\u06af\u0631 \u0635\u0627\u0631\u0641 \u0645\u0648\u062c\u0648\u062f \u0646\u06c1\u06cc\u06ba \u06c1\u06d2 \u062a\u0648\u060c \u06a9\u0648\u0626\u06cc \u062a\u0635\u062f\u06cc\u0642 \u0646\u06c1\u06cc\u06ba \u06c1\u0648\u062a\u06cc \u06c1\u06d2 \u0627\u0648\u0631 \u0627\u06cc\u06a9 \u062e\u0631\u0627\u0628\u06cc \u0648\u0627\u0642\u0639 \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4 <code>401<\/code>.<\/li>\n<li>\u0627\u06af\u0631 \u0635\u0627\u0631\u0641 \u06a9\u0627 \u06a9\u0631\u062f\u0627\u0631 \u0645\u0637\u0644\u0648\u0628\u06c1 \u06a9\u0631\u062f\u0627\u0631\u0648\u06ba \u06a9\u06cc \u0641\u06c1\u0631\u0633\u062a \u0645\u06cc\u06ba \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u060c \u062a\u0648 \u062f\u0631\u062c \u0630\u06cc\u0644 \u06c1\u0648\u062a\u0627 \u06c1\u06d2: <code>403 Forbidden<\/code> (&quot;\u0646\u0627\u06a9\u0627\u0641\u06cc \u0627\u062c\u0627\u0632\u062a\u06cc\u06ba&#8221;)\u06d4<\/li>\n<li>\u0648\u0631\u0646\u06c1 \u0648\u0627\u067e\u0633 \u06a9\u0631 \u062f\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 <code>true<\/code> \u06a9\u0646\u0679\u0631\u0648\u0644\u0631 \u06a9\u0648 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u062c\u0627\u0631\u06cc \u06c1\u06d2\u06d4<\/li>\n<\/ol>\n<h3 id=\"heading-using-rbac\">RBAC \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u06cc\u06ba\u06d4<\/h3>\n<p>\u0627\u0628 \u0622\u067e \u0627\u067e\u0646\u06d2 \u0627\u062e\u062a\u062a\u0627\u0645\u06cc \u0646\u0642\u0637\u0648\u06ba \u067e\u0631 \u06c1\u0631 \u0686\u06cc\u0632 \u06a9\u0648 \u06cc\u06a9\u062c\u0627 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u06cc\u06c1 \u0631\u0627\u0633\u062a\u06c1 \u0627\u0646 \u062a\u0645\u0627\u0645 \u0635\u0627\u0631\u0641\u06cc\u0646 \u06a9\u06cc \u0641\u06c1\u0631\u0633\u062a \u062f\u06cc\u062a\u0627 \u06c1\u06d2 \u062c\u0646 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u0635\u0631\u0641 \u0645\u0646\u062a\u0638\u0645\u06cc\u0646 \u06a9\u0648 \u06c1\u0648\u0646\u06cc \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<pre><code class=\"language-ts\">@Get('users')\n@UseGuards(\n  JwtAuthGuard,\n  RolesGuard,\n)\n@Roles(UserRole.ADMIN)\nfindUsers() {\n  return this.usersService.findAll();\n}\n<\/code><\/pre>\n<p><code>@UseGuards(JwtAuthGuard, RolesGuard)<\/code>    \u062f\u0648 \u0645\u062d\u0627\u0641\u0638\u0648\u06ba \u06a9\u0648 \u062a\u0631\u062a\u06cc\u0628 \u0633\u06d2 \u0686\u0644\u0627\u0626\u06cc\u06ba\u06d4 \u067e\u06c1\u0644\u06d2 \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0631\u06cc\u06ba \u0627\u0648\u0631 \u067e\u06be\u0631 \u0627\u067e\u0646\u06d2 \u06a9\u0631\u062f\u0627\u0631 \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0631\u06cc\u06ba\u06d4 <code>@Roles(UserRole.ADMIN)<\/code> \u06a9\u06c1\u062a\u06d2 \u06c1\u06cc\u06ba <code>RolesGuard<\/code> \u06a9\u0633 \u06a9\u0631\u062f\u0627\u0631 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2\u061f \u0622\u0631\u0688\u0631 \u06a9\u06cc \u062a\u0641\u0635\u06cc\u0644\u0627\u062a: <code>RolesGuard<\/code> \u067e\u0631 \u0645\u0646\u062d\u0635\u0631 \u06c1\u06d2 <code>req.user<\/code>\u06a9\u06d2 \u0628\u0639\u062f \u06c1\u06cc \u0645\u0648\u062c\u0648\u062f \u06c1\u06d2 <code>JwtAuthGuard<\/code> \u06cc\u06c1 \u0628\u06be\u0627\u06af \u06af\u06cc\u0627.<\/p>\n<p>\u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u062f\u0631\u062c \u0630\u06cc\u0644 \u0628\u06c1\u0627\u0624 \u06a9\u06cc \u067e\u06cc\u0631\u0648\u06cc \u06a9\u0631\u062a\u06cc \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-text\">Request\n   \u2193\nJWT valid?\n   \u2502\n   \u251c\u2500\u2500 No \u2192 401\n   \u2502\n   \u25bc\nUser identified\n   \u2193\nRole = admin?\n   \u2502\n   \u251c\u2500\u2500 No \u2192 403\n   \u2502\n   \u25bc\nController\n<\/code><\/pre>\n<h3 id=\"heading-401-vs-403\">401 \u0628\u0645\u0642\u0627\u0628\u0644\u06c1 403<\/h3>\n<p>\u06cc\u06c1 \u0641\u0631\u0642 \u0627\u06c1\u0645 \u06c1\u06d2 \u06a9\u06cc\u0648\u0646\u06a9\u06c1 \u06a9\u0648\u0688 \u06a9\u06d2 \u062f\u0648 \u0679\u06a9\u0691\u06d2 \u06a9\u0644\u0627\u0626\u0646\u0679 \u06a9\u0648 \u062f\u0648 \u0645\u062e\u062a\u0644\u0641 \u0686\u06cc\u0632\u06cc\u06ba \u0628\u062a\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u0648\u0631 \u06a9\u0644\u0627\u0626\u0646\u0679 \u06c1\u0631 \u0627\u06cc\u06a9 \u067e\u0631 \u0645\u062e\u062a\u0644\u0641 \u0631\u062f \u0639\u0645\u0644 \u0638\u0627\u06c1\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<h4 id=\"heading-401\">401<\/h4>\n<p>\u06a9\u0648\u0626\u06cc \u0631\u0627\u0633\u062a\u06c1 \u0646\u06c1\u06cc\u06ba <code>401 Unauthorized<\/code> \u062c\u0648\u0627\u0628 \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 \u06a9\u06c1 \u0633\u0631\u0648\u0631 \u0646\u06c1\u06cc\u06ba \u062c\u0627\u0646\u062a\u0627 \u06a9\u06c1 \u0622\u067e \u06a9\u0648\u0646 \u06c1\u06cc\u06ba \u06cc\u0627 \u0627\u0633 \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642 \u0646\u06c1\u06cc\u06ba \u06a9\u0631 \u0633\u06a9\u062a\u0627\u06d4 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0645\u06cc\u06ba \u0627\u06cc\u06a9 \u062f\u0631\u0633\u062a ID \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u062d\u0644 \u062a\u0648\u062b\u06cc\u0642 (\u06cc\u0627 \u062f\u0648\u0628\u0627\u0631\u06c1 \u062a\u0635\u062f\u06cc\u0642) \u06a9\u0631\u0646\u0627 \u06c1\u06d2\u06d4 \u06c1\u0645\u0627\u0631\u06cc \u0627\u06cc\u067e \u0645\u06cc\u06ba <code>401<\/code> \u0679\u0648\u06a9\u0646 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0648 \u0645\u062a\u062d\u0631\u06a9 \u06a9\u0631\u0646\u0627 \u06cc\u0627 \u0635\u0627\u0631\u0641 \u06a9\u0648 \u0644\u0627\u06af \u0627\u0646 \u0628\u06be\u06cc\u062c\u0646\u0627\u06d4<\/p>\n<pre><code class=\"language-text\">Authentication failed\n<\/code><\/pre>\n<p>\u06c1\u0627\u06ba:<\/p>\n<pre><code class=\"language-text\">Missing token\nInvalid token\nExpired token\nInvalid credentials\n<\/code><\/pre>\n<h4 id=\"heading-403\">403<\/h4>\n<p>\u06a9\u0648\u0626\u06cc \u0631\u0627\u0633\u062a\u06c1 \u0646\u06c1\u06cc\u06ba <code>403 Forbidden<\/code> \u062c\u0648\u0627\u0628 \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 \u06a9\u06c1 \u0633\u0631\u0648\u0631 \u0628\u0627\u0644\u06a9\u0644 \u062c\u0627\u0646\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u0622\u067e \u06a9\u0648\u0646 \u06c1\u06cc\u06ba \u0627\u0648\u0631 \u0622\u067e \u0627\u06cc\u0633\u0627 \u0646\u06c1\u06cc\u06ba \u06a9\u0631 \u0633\u06a9\u062a\u06d2\u06d4 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0644\u0627\u06af \u0627\u0646 \u06a9\u0631\u0646\u06d2 \u06cc\u0627 \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u062a\u0627\u0632\u06c1 \u06a9\u0631\u0646\u06d2 \u0633\u06d2 \u06a9\u0648\u0626\u06cc \u0641\u0627\u0626\u062f\u06c1 \u0646\u06c1\u06cc\u06ba \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4 \u06a9\u06cc\u0648\u0646\u06a9\u06c1 \u0634\u0646\u0627\u062e\u062a \u0679\u06be\u06cc\u06a9 \u062a\u06be\u06cc\u06d4 \u0686\u0648\u0646\u06a9\u06c1 \u0635\u0627\u0631\u0641 \u0645\u062c\u0627\u0632 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u060c \u0627\u0633 \u0644\u06cc\u06d2 \u06a9\u0644\u0627\u0626\u0646\u0679 \u06a9\u0648 \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2 &quot;\u0631\u0633\u0627\u0626\u06cc \u0633\u06d2 \u0627\u0646\u06a9\u0627\u0631&#8221; \u067e\u06cc\u063a\u0627\u0645 \u0688\u0633\u067e\u0644\u06d2 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<pre><code class=\"language-text\">Authentication succeeded\nbut authorization failed\n<\/code><\/pre>\n<p>\u06c1\u0627\u06ba:<\/p>\n<pre><code class=\"language-text\">User = USER\nRequired = ADMIN\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u0636\u0631\u0648\u0631\u06cc \u06c1\u06d2 \u06a9\u06cc\u0648\u0646\u06a9\u06c1 \u0627\u0646 \u06a9\u0648 \u0645\u0644\u0627\u0646\u06d2 \u0633\u06d2 \u062d\u0642\u06cc\u0642\u06cc \u0645\u0633\u0627\u0626\u0644 \u067e\u06cc\u062f\u0627 \u06c1\u0648\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 <code>401<\/code> \u0627\u06af\u0631 \u0627\u062c\u0627\u0632\u062a \u06a9\u0627 \u0645\u0633\u0626\u0644\u06c1 \u06c1\u06d2 \u062a\u0648\u060c \u0627\u0646\u06af\u0648\u0644\u0631 \u0627\u06cc\u067e \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0631\u0646\u06d2 \u0627\u0648\u0631 \u062f\u06c1\u0631\u0627\u0646\u06d2 \u06a9\u06cc \u06a9\u0648\u0634\u0634 \u06a9\u0631\u06d2 \u06af\u06cc\u060c \u0627\u0648\u0631 \u0627\u06af\u0631 \u06cc\u06c1 \u0648\u0627\u067e\u0633 \u0622\u062c\u0627\u062a\u06cc \u06c1\u06d2\u06d4 <code>403<\/code> \u06af\u0645\u0634\u062f\u06c1 \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u0635\u0648\u0631\u062a \u0645\u06cc\u06ba\u060c \u0627\u06cc\u067e \u06a9\u0648 \u06cc\u06c1 \u0646\u06c1\u06cc\u06ba \u0645\u0639\u0644\u0648\u0645 \u06c1\u0648\u06af\u0627 \u06a9\u06c1 \u0627\u0633\u06d2 \u062f\u0648\u0628\u0627\u0631\u06c1 \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2\u06d4 \u06cc\u0627\u062f \u0631\u06a9\u06be\u0646\u06d2 \u06a9\u06d2 \u0641\u0648\u0631\u06cc \u0637\u0631\u06cc\u0642\u06d2:<\/p>\n<pre><code class=\"language-text\">401 \u2192 Who are you?\n\n403 \u2192 We know who you are,\n      but you're not allowed.\n<\/code><\/pre>\n<h3 id=\"heading-public-routes\">\u0639\u0648\u0627\u0645\u06cc \u0631\u0627\u0633\u062a\u06c1<\/h3>\n<p>\u0627\u06af\u0631 \u062a\u062d\u0641\u0638 \u0688\u06cc\u0641\u0627\u0644\u0679 \u06c1\u06d2\u060c \u062a\u0648 \u0622\u067e \u06a9\u0648 \u06cc\u06c1 \u0628\u062a\u0627\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u0637\u0631\u06cc\u0642\u06c1 \u062f\u0631\u06a9\u0627\u0631 \u06c1\u0648\u06af\u0627 \u06a9\u06c1 \u06a9\u0648\u0646 \u0633\u06d2 \u0627\u062e\u062a\u062a\u0627\u0645\u06cc \u0646\u0642\u0637\u06d2 \u06a9\u06be\u0644\u06d2 \u06c1\u0648\u0646\u06d2 \u0686\u0627\u06c1\u0626\u06cc\u06ba\u060c \u062c\u06cc\u0633\u06d2 \u0644\u0627\u06af \u0627\u0646 \u0627\u0648\u0631 \u0631\u062c\u0633\u0679\u0631\u06cc\u0634\u0646\u06d4 \u062f\u0633\u062a\u06cc \u0637\u0648\u0631 \u067e\u0631 \u06c1\u0631 \u062c\u06af\u06c1 \u06af\u0627\u0631\u0688\u0632 \u06a9\u0648 \u0634\u0627\u0645\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2 <code>@Public()<\/code> \u0688\u06cc\u06a9\u0648\u0631\u06cc\u0679\u0631\u06d4 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0627\u06cc\u06a9 \u06c1\u06cc \u0645\u06cc\u0679\u0627 \u0688\u06cc\u0679\u0627 \u0679\u06cc\u06a9\u0646\u0627\u0644\u0648\u062c\u06cc \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2. <code>@Roles()<\/code>:<\/p>\n<pre><code class=\"language-ts\">export const IS_PUBLIC_KEY =\n  'isPublic';\n\nexport const Public = () =>\n  SetMetadata(\n    IS_PUBLIC_KEY,\n    true,\n  );\n<\/code><\/pre>\n<p>\u067e\u06be\u0631 \u0627\u0633\u06d2 \u0627\u0633 \u0631\u0627\u0633\u062a\u06d2 \u067e\u0631 \u0644\u0627\u06af\u0648 \u06a9\u0631\u06cc\u06ba \u062c\u0633\u06d2 \u06a9\u06be\u0648\u0644\u0646\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2 (\u062c\u06cc\u0633\u06d2 \u0644\u0627\u06af \u0627\u0646 \u0627\u06cc\u0646\u0688 \u067e\u0648\u0627\u0626\u0646\u0679)\u06d4<\/p>\n<pre><code class=\"language-ts\">@Post('login')\n@Public()\nlogin() {}\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u0622\u067e \u06a9\u0648 \u062a\u0635\u062f\u06cc\u0642 \u06a9\u06d2 \u0645\u062d\u0627\u0641\u0638\u0648\u06ba \u06a9\u0648 \u0639\u0627\u0644\u0645\u06cc \u0628\u0646\u0627\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4 \u06af\u0627\u0631\u0688 \u06a9\u0648 \u0639\u0627\u0644\u0645\u06cc \u0628\u0646\u0627\u0646\u06d2 \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 \u0627\u0633\u06d2 \u067e\u0648\u0631\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u0628\u0627\u0631 \u0631\u062c\u0633\u0679\u0631 \u06a9\u0631\u0646\u0627\u060c \u062c\u06cc\u0633\u06d2 <code>APP_GUARD<\/code>) \u0627\u0633\u06d2 \u0634\u0627\u0645\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2\u060c \u06cc\u06c1 \u062e\u0648\u062f \u0628\u062e\u0648\u062f \u062a\u0645\u0627\u0645 \u0631\u0627\u0633\u062a\u0648\u06ba \u067e\u0631 \u0686\u0644\u06d2 \u06af\u0627\u06d4 <code>@UseGuards(JwtAuthGuard)<\/code> \u06c1\u0631 \u06a9\u0646\u0679\u0631\u0648\u0644\u0631 \u06cc\u0627 \u0637\u0631\u06cc\u0642\u06c1 \u067e\u0631\u06d4 \u06af\u0644\u0648\u0628\u0644 \u06af\u0627\u0631\u0688 \u0645\u0646\u062f\u0631\u062c\u06c1 \u0630\u06cc\u0644 \u0686\u06cc\u06a9 \u06a9\u0631\u062a\u0627 \u06c1\u06d2: <code>@Public()<\/code> \u067e\u06c1\u0644\u0627: \u0627\u06af\u0631 \u0631\u0627\u0633\u062a\u06d2 \u0645\u06cc\u06ba \u0648\u06c1 \u0631\u0627\u0633\u062a\u06c1 \u06c1\u06d2\u060c \u062a\u0648 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u06c1\u06d2\u060c \u0628\u0635\u0648\u0631\u062a \u062f\u06cc\u06af\u0631 \u0639\u0627\u0645 JWT \u062a\u0648\u062b\u06cc\u0642 \u067e\u0631 \u0639\u0645\u0644 \u062f\u0631\u0622\u0645\u062f \u06a9\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0641\u0646 \u062a\u0639\u0645\u06cc\u0631 \u0645\u0646\u062f\u0631\u062c\u06c1 \u0630\u06cc\u0644 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-text\">Request\n  \u2193\nGlobal Auth Guard\n  \u2193\n@Public()?\n \u251c\u2500\u2500 yes \u2192 allow\n \u2514\u2500\u2500 no\n      \u2193\nJWT authentication\n      \u2193\nAuthorization\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u0627\u06a9\u062b\u0631 \u0632\u06cc\u0627\u062f\u06c1 \u0645\u062d\u0641\u0648\u0638 \u06c1\u0648\u062a\u0627 \u06c1\u06d2 \u06a9\u06cc\u0648\u0646\u06a9\u06c1 \u0646\u0626\u06d2 \u0627\u06cc\u0646\u0688 \u067e\u0648\u0627\u0626\u0646\u0679\u0633 \u0628\u0637\u0648\u0631 \u0688\u06cc\u0641\u0627\u0644\u0679 \u0645\u062d\u0641\u0648\u0638 \u06c1\u0648\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0627\u06af\u0631 \u06a9\u0648\u0626\u06cc \u0688\u0648\u06cc\u0644\u067e\u0631 \u0646\u0626\u06d2 \u0631\u0648\u0679 \u067e\u0631 \u06af\u0627\u0631\u0688\u0632 \u0634\u0627\u0645\u0644 \u06a9\u0631\u0646\u0627 \u0628\u06be\u0648\u0644 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u060c \u062a\u0628 \u0628\u06be\u06cc \u06cc\u06c1 \u0645\u062d\u0641\u0648\u0638 \u06c1\u06d2 \u0627\u0648\u0631 \u0627\u0633 \u0631\u0627\u0633\u062a\u06d2 \u06a9\u0648 \u0639\u0648\u0627\u0645 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06a9\u06be\u0648\u0644\u0646\u0627 \u0627\u06cc\u06a9 \u062f\u0627\u0646\u0634\u0645\u0646\u062f\u0627\u0646\u06c1 \u0627\u0646\u062a\u062e\u0627\u0628 \u06c1\u0648\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<h2 id=\"heading-21-csrf\">21. \u0633\u06cc \u0627\u06cc\u0633 \u0622\u0631 \u0627\u06cc\u0641<\/h2>\n<p>\u06a9\u0631\u0627\u0633 \u0633\u0627\u0626\u0679 \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06cc \u062c\u0639\u0644 \u0633\u0627\u0632\u06cc \u0627\u06cc\u06a9 \u0645\u0633\u0626\u0644\u06c1 \u0628\u0646 \u062c\u0627\u062a\u06cc \u06c1\u06d2 \u062c\u0628 \u0628\u0631\u0627\u0624\u0632\u0631 \u062e\u0648\u062f \u0628\u062e\u0648\u062f \u0627\u0633\u0646\u0627\u062f\u060c \u062c\u06cc\u0633\u06d2 \u06a9\u0648\u06a9\u06cc\u0632\u060c \u06a9\u0648 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0645\u0646\u0633\u0644\u06a9 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 HttpOnly JavaScript \u0633\u06d2 \u06a9\u0648\u06a9\u06cc \u06a9\u06cc \u0631\u0627\u0632\u062f\u0627\u0631\u06cc \u06a9\u06cc \u062d\u0641\u0627\u0638\u062a \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0644\u06cc\u06a9\u0646 \u0628\u0631\u0627\u0624\u0632\u0631 \u06a9\u0648 \u06a9\u0648\u06a9\u06cc\u0632 \u0628\u06be\u06cc\u062c\u0646\u06d2 \u0633\u06d2 \u0646\u06c1\u06cc\u06ba \u0631\u0648\u06a9\u062a\u0627\u06d4<\/p>\n<p>\u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u06a9\u0648\u06a9\u06cc \u0645\u06cc\u06ba \u0645\u062d\u0641\u0648\u0638 \u06a9\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u06a9\u0648\u06a9\u06cc\u0632 \u0645\u06cc\u06ba \u0627\u06c1\u0645 \u062e\u0635\u0648\u0635\u06cc\u0627\u062a \u06c1\u06cc\u06ba\u06d4 \u0627\u0633 \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u0622\u067e \u06a9\u0627 \u0628\u0631\u0627\u0624\u0632\u0631 \u062e\u0648\u062f \u0628\u062e\u0648\u062f \u06a9\u0648\u06a9\u06cc \u06a9\u06d2 \u0627\u0635\u0648\u0644\u0648\u06ba \u06a9\u06cc \u0628\u0646\u06cc\u0627\u062f \u067e\u0631 \u0622\u067e \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0627\u06cc\u06a9 \u06a9\u0648\u06a9\u06cc \u0645\u0646\u0633\u0644\u06a9 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u06cc\u06c1 CSRF \u062a\u062d\u0641\u0638\u0627\u062a \u067e\u06cc\u062f\u0627 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0628\u0646\u06cc\u0627\u062f\u06cc \u0645\u0633\u0626\u0644\u06c1 \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0635\u0627\u0631\u0641 \u06a9\u06cc \u062c\u0627\u0646\u0628 \u0633\u06d2 \u0627\u06cc\u06a9 \u062f\u0631\u0633\u062a \u06a9\u0648\u06a9\u06cc \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0628\u06be\u06cc\u062c\u06cc \u062c\u0627\u062a\u06cc \u06c1\u06d2\u060c \u0644\u06cc\u06a9\u0646 \u0635\u0627\u0631\u0641 \u06a9\u0627 \u0627\u0633\u06d2 \u0628\u06be\u06cc\u062c\u0646\u06d2 \u06a9\u0627 \u06a9\u0648\u0626\u06cc \u0627\u0631\u0627\u062f\u06c1 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u0633\u0631\u0648\u0631 \u0627\u06cc\u06a9 \u062f\u0631\u0633\u062a \u06a9\u0648\u06a9\u06cc \u06a9\u06cc \u062c\u0627\u0646\u0686 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u0627\u06a9\u06cc\u0644\u06d2 \u06a9\u0648\u06a9\u06cc\u0632 \u06c1\u0645\u06cc\u06ba \u06cc\u06c1 \u0646\u06c1\u06cc\u06ba \u0628\u062a\u0627\u062a\u06cc \u06c1\u06cc\u06ba \u06a9\u06c1 \u0622\u06cc\u0627 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06c1\u0645\u0627\u0631\u06cc \u0627\u06cc\u067e \u0633\u06d2 \u0622\u0626\u06cc \u06c1\u06d2 \u06cc\u0627 \u06a9\u0633\u06cc \u0627\u0648\u0631 \u0648\u06cc\u0628 \u0633\u0627\u0626\u0679 \u0633\u06d2\u06d4 \u0631\u06cc\u0627\u0633\u062a \u06a9\u06cc \u062a\u0628\u062f\u06cc\u0644\u06cc \u06a9\u06d2 \u0627\u062e\u062a\u062a\u0627\u0645\u06cc \u0646\u06a9\u0627\u062a \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u0633 \u0637\u0631\u062d: <code>\/auth\/refresh<\/code> \u06cc\u0627 <code>\/auth\/logout<\/code>\u06cc\u06c1 \u0646\u0642\u0635\u0627\u0646 \u062f\u06c1 \u0633\u0627\u0626\u0679\u0633 \u06a9\u0648 \u0644\u0627\u06af \u0627\u0646 \u0635\u0627\u0631\u0641 \u06a9\u06d2 \u062a\u0646\u0627\u0638\u0631 \u0645\u06cc\u06ba \u06a9\u0627\u0631\u0631\u0648\u0627\u0626\u06cc\u0648\u06ba \u06a9\u0648 \u0645\u062a\u062d\u0631\u06a9 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0641\u0631\u0636 \u06a9\u0631\u06cc\u06ba:<\/p>\n<pre><code class=\"language-text\">User logged into our-app.com\n\nthen visits\n\nevil.com\n<\/code><\/pre>\n<p>\u0646\u0642\u0635\u0627\u0646 \u062f\u06c1 \u0633\u0627\u0626\u0679\u0633 \u06a9\u0648\u0634\u0634 \u06a9\u0631 \u0633\u06a9\u062a\u06cc \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-http\">POST https:\/\/our-app.com\/auth\/refresh\n<\/code><\/pre>\n<p>\u0622\u067e \u06a9\u0627 \u0628\u0631\u0627\u0624\u0632\u0631 \u062e\u0648\u062f \u0628\u062e\u0648\u062f \u06a9\u0648\u06a9\u06cc\u0632 \u06a9\u0627 \u0627\u0646\u062a\u0638\u0627\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0633 \u0645\u0633\u0626\u0644\u06d2 \u0633\u06d2 \u0646\u0645\u0679\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2\u060c \u0622\u067e CSRF \u062f\u0641\u0627\u0639 \u0634\u0627\u0645\u0644 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0645\u0646\u062f\u0631\u062c\u06c1 \u0630\u06cc\u0644 \u0630\u06cc\u0644\u06cc \u062d\u0635\u0648\u06ba \u0645\u06cc\u06ba\u060c \u06c1\u0645 \u062a\u06cc\u0646 \u06a9\u0648 \u062f\u06cc\u06a9\u06be\u06cc\u06ba \u06af\u06d2\u06d4 <code>SameSite<\/code> \u06a9\u0648\u06a9\u06cc \u06a9\u06cc \u062e\u0635\u0648\u0635\u06cc\u0627\u062a\u060c CSRF \u0679\u0648\u06a9\u0646\u060c \u0627\u0648\u0631 \u06af\u0627\u0631\u0688\u0632 \u062c\u0648 \u0627\u0646 \u06a9\u06cc \u062c\u0627\u0646\u0686 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<h3 id=\"heading-samesite\">\u0627\u06cc\u06a9 \u06c1\u06cc \u0633\u0627\u0626\u0679<\/h3>\n<p><code>SameSite<\/code>    \u0627\u06cc\u06a9 \u06a9\u0648\u06a9\u06cc \u06a9\u0627 \u0648\u0635\u0641 \u062c\u0648 \u0628\u0631\u0627\u0624\u0632\u0631 \u06a9\u0648 \u0628\u062a\u0627\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u06a9\u0633\u06cc \u062f\u0648\u0633\u0631\u06cc \u0633\u0627\u0626\u0679 \u0633\u06d2 \u0622\u0646\u06d2 \u0648\u0627\u0644\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06d2 \u0644\u06cc\u06d2 \u06a9\u0648\u06a9\u06cc \u06a9\u0628 \u0628\u06be\u06cc\u062c\u0646\u06cc \u06c1\u06d2\u06d4 \u06a9\u06d2 \u0633\u0627\u062a\u06be <code>Strict<\/code>\u0628\u0631\u0627\u0624\u0632\u0631 \u0635\u0631\u0641 \u0627\u0633 \u0635\u0648\u0631\u062a \u0645\u06cc\u06ba \u06a9\u0648\u06a9\u06cc\u0632 \u0628\u06be\u06cc\u062c\u062a\u06d2 \u06c1\u06cc\u06ba \u062c\u0628 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0627\u0633\u06cc \u0633\u0627\u0626\u0679 \u0633\u06d2 \u0622\u062a\u06cc \u06c1\u06d2 \u062c\u0633 \u06a9\u06cc \u06a9\u0648\u06a9\u06cc \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4 \u06a9\u06d2 \u0633\u0627\u062a\u06be <code>Lax<\/code>\u06cc\u06c1 \u0679\u0627\u067e \u0644\u06cc\u0648\u0644 \u0646\u06cc\u0648\u06cc\u06af\u06cc\u0634\u0646 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u0628\u06be\u06cc\u062c\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u060c \u062c\u06cc\u0633\u06d2 \u06a9\u06c1 \u0644\u0646\u06a9 \u06a9\u0644\u06a9\u0633\u06d4 \u06a9\u06d2 \u0633\u0627\u062a\u06be <code>None<\/code>\u0627\u0633\u06d2 \u06c1\u0631 \u06a9\u0631\u0627\u0633 \u0633\u0627\u0626\u0679 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06d2 \u0644\u06cc\u06d2 \u0628\u06be\u06cc\u062c\u06cc\u06ba (\u0627\u0648\u0631 <code>Secure<\/code>)\u06d4<\/p>\n<p>\u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0648\u06a9\u06cc\u0632 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631 \u0633\u06a9\u062a\u06cc \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-ts\">sameSite: 'strict'\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u0627\u06cc\u06a9 \u0645\u0641\u06cc\u062f \u062f\u0641\u0627\u0639\u06cc \u06af\u06c1\u0631\u0627\u0626\u06cc \u0648\u0627\u0644\u0627 \u0633\u06cc\u0679 \u0627\u067e \u06c1\u06d2\u060c \u0644\u06cc\u06a9\u0646 \u06cc\u06c1 \u0627\u06cc\u06a9 \u0645\u06a9\u0645\u0644 CSRF \u062d\u06a9\u0645\u062a \u0639\u0645\u0644\u06cc \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u06a9\u0648\u06a9\u06cc \u06a9\u0627 \u0631\u0648\u06cc\u06c1 \u0641\u0631\u0646\u0679 \u0627\u06cc\u0646\u0688 \u0627\u0648\u0631 \u0628\u06cc\u06a9 \u0627\u06cc\u0646\u0688 \u0633\u0627\u0626\u0679\u0633\u060c \u06a9\u0648\u06a9\u06cc \u0688\u0648\u0645\u06cc\u0646\/\u067e\u0627\u062a\u06be \u06a9\u06d2 \u062f\u0631\u0645\u06cc\u0627\u0646 \u062a\u0639\u0644\u0642 \u067e\u0631 \u0645\u0646\u062d\u0635\u0631 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u0622\u06cc\u0627 \u06a9\u0644\u0627\u0626\u0646\u0679 \u0627\u0648\u0631 CORS \u06a9\u0646\u0641\u06cc\u06af\u0631\u06cc\u0634\u0646 \u0645\u06cc\u06ba \u0627\u0633\u0646\u0627\u062f \u06a9\u0648 \u0641\u0639\u0627\u0644 \u06a9\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u062a\u0627\u06c1\u0645\u060c \u06a9\u0648\u06a9\u06cc \u06a9\u0627 \u0631\u0648\u06cc\u06c1 \u0627\u0633 \u0628\u0627\u062a \u067e\u0631 \u0645\u0646\u062d\u0635\u0631 \u06c1\u0648\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u0622\u06cc\u0627 \u0641\u0631\u0646\u0679 \u0627\u06cc\u0646\u0688 \u0627\u0648\u0631 \u0628\u06cc\u06a9 \u0627\u06cc\u0646\u0688 \u0627\u06cc\u06a9 \u06c1\u06cc \u0627\u0635\u0644\u060c \u0627\u06cc\u06a9 \u06c1\u06cc \u0633\u0627\u0626\u0679\u060c \u06cc\u0627 \u06a9\u0631\u0627\u0633 \u0633\u0627\u0626\u0679 \u0633\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u06a9\u0631\u0627\u0633 \u0633\u0627\u0626\u0679 \u06a9\u06cc \u062a\u0639\u06cc\u0646\u0627\u062a\u06cc\u0648\u06ba \u06a9\u06d2 \u0644\u06cc\u06d2\u060c \u0622\u067e \u06a9\u0648 \u0636\u0631\u0648\u0631\u062a \u06c1\u0648 \u0633\u06a9\u062a\u06cc \u06c1\u06d2:<\/p>\n<pre><code class=\"language-text\">SameSite=None\nSecure=true\n<\/code><\/pre>\n<p>\u0648\u0627\u0636\u062d CSRF \u062a\u062d\u0641\u0638 \u0628\u06be\u06cc \u0634\u0627\u0645\u0644 \u06c1\u06d2\u06d4 \u06a9\u0644\u0627\u0626\u0646\u0679 \u06a9\u0648 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2: <code>withCredentials: true<\/code>\u0622\u067e \u06a9\u06d2 API \u06a9\u0648 \u0627\u06cc\u06a9 \u062f\u0631\u0633\u062a \u0627\u0648\u0631 \u0642\u0627\u0628\u0644 \u0628\u06be\u0631\u0648\u0633\u06c1 \u0641\u0631\u0646\u0679 \u0627\u06cc\u0646\u0688 \u0627\u0635\u0644\u06cc\u062a \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u0633\u0646\u0627\u062f \u06a9\u0648 \u0642\u0628\u0648\u0644 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u0627\u0633\u0646\u0627\u062f \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u0648 \u0648\u0627\u0626\u0644\u0688 \u06a9\u0627\u0631\u0688 CORS \u0630\u0631\u0627\u0626\u0639 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0646\u06c1\u06cc\u06ba \u0645\u0644\u0627\u06cc\u0627 \u062c\u0627\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<p>\u0644\u06c1\u0630\u0627\u060c \u0622\u067e \u06a9\u0648 \u0627\u067e\u0646\u06cc \u06a9\u0648\u06a9\u06cc \u06a9\u06cc \u062a\u0631\u062a\u06cc\u0628 \u06a9\u0648 \u0627\u067e\u0646\u06d2 \u062a\u0639\u06cc\u0646\u0627\u062a\u06cc \u0641\u0646 \u062a\u0639\u0645\u06cc\u0631 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0688\u06cc\u0632\u0627\u0626\u0646 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2\u06d4 SameSite \u06af\u06c1\u0631\u0627\u0626\u06cc \u0645\u06cc\u06ba \u062f\u0641\u0627\u0639 \u06c1\u06d2. \u06cc\u06c1 \u062d\u06cc\u062b\u06cc\u062a \u06a9\u06cc \u062a\u0628\u062f\u06cc\u0644\u06cc \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u06a9\u0631\u0646\u06d2 \u06a9\u0627 \u0645\u062a\u0628\u0627\u062f\u0644 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4<\/p>\n<h3 id=\"heading-csrf-token\">CSRF \u0679\u0648\u06a9\u0646<\/h3>\n<p>CSRF \u0679\u0648\u06a9\u0646 \u0627\u06cc\u06a9 \u0628\u06d2 \u062a\u0631\u062a\u06cc\u0628 \u0642\u062f\u0631 \u06c1\u06d2 \u062c\u0648 \u0633\u0631\u0648\u0631 \u0627\u067e\u0646\u06d2 \u0641\u0631\u0646\u0679 \u0627\u06cc\u0646\u0688 \u06a9\u0648 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u0641\u0631\u0646\u0679 \u0627\u06cc\u0646\u0688 \u06a9\u0648 \u0627\u0633\u06d2 \u0631\u06cc\u0627\u0633\u062a \u0645\u06cc\u06ba \u062a\u0628\u062f\u06cc\u0644\u06cc \u06a9\u06cc \u06c1\u0631 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0648\u0627\u067e\u0633 \u0628\u06be\u06cc\u062c\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u0627\u06cc\u06a9 \u0628\u062f\u0646\u06cc\u062a\u06cc \u067e\u0631 \u0645\u0628\u0646\u06cc \u0633\u0627\u0626\u0679 \u0628\u0631\u0627\u0624\u0632\u0631 \u06a9\u0648 \u06a9\u0648\u06a9\u06cc \u0645\u0646\u0633\u0644\u06a9 \u06a9\u0631\u0646\u06d2 \u06a9\u0627 \u0633\u0628\u0628 \u0628\u0646 \u0633\u06a9\u062a\u06cc \u06c1\u06d2\u060c \u0644\u06cc\u06a9\u0646 \u06cc\u06c1 \u06a9\u0648\u06a9\u06cc \u06a9\u0648 \u0646\u06c1\u06cc\u06ba \u067e\u0691\u06be \u0633\u06a9\u062a\u06cc \u06cc\u0627 \u0688\u0648\u0645\u06cc\u0646 \u06a9\u06d2 \u0644\u06cc\u06d2 \u062d\u0633\u0628 \u0636\u0631\u0648\u0631\u062a \u06c1\u06cc\u0688\u0631 \u0633\u06cc\u0679 \u0646\u06c1\u06cc\u06ba \u06a9\u0631 \u0633\u06a9\u062a\u06cc\u060c \u0627\u0633 \u0644\u06cc\u06d2 \u06cc\u06c1 \u0645\u0645\u0627\u062b\u0644 \u0679\u0648\u06a9\u0646 \u0646\u06c1\u06cc\u06ba \u0628\u0646\u0627 \u0633\u06a9\u062a\u06cc\u06d4 \u0633\u0631\u0648\u0631 \u0635\u0631\u0641 \u0627\u0633 \u0635\u0648\u0631\u062a \u0645\u06cc\u06ba \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0642\u0628\u0648\u0644 \u06a9\u0631\u06d2 \u06af\u0627 \u062c\u0628 \u06c1\u06cc\u0688\u0631 \u0645\u06cc\u06ba \u0645\u0648\u062c\u0648\u062f \u0679\u0648\u06a9\u0646 \u06a9\u0648\u06a9\u06cc \u0645\u06cc\u06ba \u0645\u0648\u062c\u0648\u062f \u0679\u0648\u06a9\u0646 \u0633\u06d2 \u0645\u06cc\u0644 \u06a9\u06be\u0627\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0639\u0627\u0645 \u067e\u06cc\u0679\u0631\u0646 \u0645\u06cc\u06ba \u0634\u0627\u0645\u0644 \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-text\">HttpOnly Cookie\nrefresh_token\n\nRegular Cookie\ncsrf_token\n<\/code><\/pre>\n<p>\u06a9\u06c1 <code>csrf_token<\/code> \u06cc\u06c1 \u0627\u06cc\u06a9 \u0628\u0627\u0642\u0627\u0639\u062f\u06c1 (\u063a\u06cc\u0631 \u0635\u0631\u0641 Http) \u06a9\u0648\u06a9\u06cc \u06c1\u06d2 \u062c\u0633\u06d2 Angular \u067e\u0691\u06be \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 \u067e\u0691\u06be\u0646\u06d2 \u06a9\u0627 \u0632\u0627\u0648\u06cc\u06c1:<\/p>\n<pre><code class=\"language-text\">csrf_token\n<\/code><\/pre>\n<p>\u0627\u0633\u06d2 \u062d\u0633\u0628 \u0636\u0631\u0648\u0631\u062a \u06c1\u06cc\u0688\u0631 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0648\u0627\u067e\u0633 \u0628\u06be\u06cc\u062c\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-http\">X-CSRF-Token: <token>\n<\/token><\/code><\/pre>\n<p>\u0633\u0631\u0648\u0631 \u067e\u06be\u0631 \u0686\u06cc\u06a9 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u0622\u06cc\u0627 \u062f\u0648\u0646\u0648\u06ba \u0642\u062f\u0631\u06cc\u06ba \u0628\u0631\u0627\u0628\u0631 \u06c1\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-text\">Cookie csrf_token\n        ==\nX-CSRF-Token\n<\/code><\/pre>\n<p>\u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0628\u0630\u0627\u062a \u062e\u0648\u062f HttpOnly \u0631\u06c1\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<h3 id=\"heading-csrf-guard\">\u0633\u06cc \u0627\u06cc\u0633 \u0622\u0631 \u0627\u06cc\u0641 \u06af\u0627\u0631\u0688<\/h3>\n<p>CSRF \u06af\u0627\u0631\u0688 \u0627\u06cc\u06a9 NestJS \u06af\u0627\u0631\u0688 \u06c1\u06d2 \u062c\u0648 \u0633\u0631\u0648\u0631 \u067e\u0631 \u0627\u0633 \u0686\u06cc\u06a9 \u06a9\u0648 \u0627\u0646\u062c\u0627\u0645 \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4 \u0622\u0626\u06cc\u06d2 \u0645\u062d\u0641\u0648\u0638 \u0637\u0631\u06cc\u0642\u0648\u06ba \u06a9\u0648 \u0686\u06be\u0648\u0691 \u062f\u06cc\u06ba (\u062c\u0648 \u0631\u06cc\u0627\u0633\u062a \u06a9\u0648 \u062a\u0628\u062f\u06cc\u0644 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba) \u0627\u0648\u0631 \u06a9\u0648\u0688 \u06a9\u0648 \u062f\u06cc\u06a9\u06be\u06cc\u06ba \u062c\u0648 \u062f\u06cc\u06af\u0631 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u0648 \u0645\u0633\u062a\u0631\u062f \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u062c\u0648 \u063a\u0627\u0626\u0628 \u06c1\u06cc\u06ba \u06cc\u0627 \u0628\u0635\u0648\u0631\u062a \u062f\u06cc\u06af\u0631 \u06a9\u0648\u06a9\u06cc\u0632 \u0627\u0648\u0631 \u06c1\u06cc\u0688\u0631 \u0679\u0648\u06a9\u0646\u0632 \u063a\u0627\u0626\u0628 \u06c1\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-ts\">@Injectable()\nexport class CsrfGuard\n  implements CanActivate {\n\n  canActivate(\n    context: ExecutionContext,\n  ): boolean {\n\n    const request =\n      context\n        .switchToHttp()\n        .getRequest();\n\n    const safeMethods = [\n      'GET',\n      'HEAD',\n      'OPTIONS',\n    ];\n\n    if (\n      safeMethods.includes(\n        request.method,\n      )\n    ) {\n      return true;\n    }\n\n    const cookieToken =\n      request.cookies?.csrf_token;\n\n    const headerToken =\n      request.headers[\n        'x-csrf-token'\n      ];\n\n    if (\n      !cookieToken ||\n      !headerToken ||\n      cookieToken !== headerToken\n    ) {\n      throw new ForbiddenException(\n        'Invalid CSRF token',\n      );\n    }\n\n    return true;\n  }\n}\n<\/code><\/pre>\n<p>\u067e\u06cc\u062f\u0627\u0648\u0627\u0631\u06cc \u0646\u0638\u0627\u0645 \u0645\u06cc\u06ba\u060c \u0622\u067e \u062f\u0648 \u0679\u0648\u06a9\u0646 \u0627\u0642\u062f\u0627\u0631 \u06a9\u0627 \u0645\u0648\u0627\u0632\u0646\u06c1 \u06a9\u0631\u0646\u06d2 \u0627\u0648\u0631 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642 \u067e\u0631 \u063a\u0648\u0631 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u0633\u062a\u0642\u0644 \u0648\u0642\u062a \u06a9\u0627 \u0645\u0648\u0627\u0632\u0646\u06c1 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 <code>Origin<\/code> \u0627\u06cc\u06a9 \u0627\u0636\u0627\u0641\u06cc \u062f\u0641\u0627\u0639 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631\u06d4 \u0645\u0632\u06cc\u062f \u0628\u0631\u0622\u06ba\u060c \u0627\u06cc\u067e\u0644\u06cc\u06a9\u06cc\u0634\u0646 \u06a9\u0648 \u0644\u0627\u0632\u0645\u06cc \u0637\u0648\u0631 \u067e\u0631 \u0627\u06cc\u06a9 \u062e\u0641\u06cc\u06c1 \u06a9\u0631\u062f\u06c1 \u0627\u0648\u0631 \u063a\u06cc\u0631 \u0645\u062a\u0648\u0642\u0639 CSRF \u0679\u0648\u06a9\u0646 \u062a\u06cc\u0627\u0631 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2 \u0627\u0648\u0631 \u0627\u0633\u06d2 \u0627\u0631\u0627\u062f\u06cc \u0637\u0631\u06cc\u0642\u06c1 \u06a9\u0627\u0631 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u0627\u0646\u06af\u0648\u0644\u0631 \u06a9\u0648 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<p>\u0686\u0648\u0646\u06a9\u06c1 \u06a9\u0648\u06a9\u06cc\u0632 \u0627\u0648\u0631 \u06c1\u06cc\u0688\u0631\u0632 \u06a9\u0627 \u0645\u0648\u0627\u0632\u0646\u06c1 \u06a9\u0631\u0646\u0627 \u0688\u06cc\u0632\u0627\u0626\u0646 \u06a9\u0627 \u0635\u0631\u0641 \u0627\u06cc\u06a9 \u062d\u0635\u06c1 \u06c1\u06d2\u060c \u0627\u0633 \u0644\u06cc\u06d2 \u06c1\u0645 \u0622\u067e \u06a9\u06d2 \u0627\u0635\u0644 \u0641\u0631\u0646\u0679 \u0627\u06cc\u0646\u0688 \u0627\u0648\u0631 \u0628\u06cc\u06a9 \u0627\u06cc\u0646\u0688 \u0688\u0648\u0645\u06cc\u0646\u0632 \u0627\u0648\u0631 \u067e\u0631\u0627\u06a9\u0633\u06cc \u06a9\u0646\u0641\u06cc\u06af\u0631\u06cc\u0634\u0646 \u06a9\u06d2 \u062e\u0644\u0627\u0641 \u067e\u0648\u0631\u06d2 \u0628\u06c1\u0627\u0624 \u06a9\u0648 \u0686\u06cc\u06a9 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u062a\u062c\u0648\u06cc\u0632 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<h2 id=\"heading-22-redis\">22. \u0631\u06cc\u0688\u06cc\u0633<\/h2>\n<p>Redis \u0642\u0644\u06cc\u0644 \u0627\u0644\u0645\u062f\u062a \u0645\u0634\u062a\u0631\u06a9\u06c1 \u0631\u06cc\u0627\u0633\u062a \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u0641\u06cc\u062f \u06c1\u06d2\u060c \u0628\u0634\u0645\u0648\u0644 \u0634\u0631\u062d \u0645\u062d\u062f\u0648\u062f \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u06a9\u0627\u0624\u0646\u0679\u0631\u0632\u06d4 \u0627\u0633 \u06a9\u06cc \u0648\u062c\u06c1 \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u0645\u062a\u0639\u062f\u062f API \u0645\u062b\u0627\u0644\u06cc\u06ba \u0627\u06cc\u06a9 \u06c1\u06cc \u0627\u0633\u0679\u0648\u0631\u06cc\u062c \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631 \u0633\u06a9\u062a\u06cc \u06c1\u06cc\u06ba\u06d4 \u062c\u0628 \u062a\u06a9 \u06a9\u06c1 \u06cc\u06c1 \u0627\u06cc\u06a9 \u0648\u0627\u0636\u062d \u0622\u0631\u06a9\u06cc\u0679\u06cc\u06a9\u0686\u0631\u0644 \u0627\u0646\u062a\u062e\u0627\u0628 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u060c \u06cc\u06c1 \u0635\u0627\u0631\u0641 \u06a9\u06cc \u0634\u0646\u0627\u062e\u062a \u06cc\u0627 \u0637\u0648\u06cc\u0644 \u0627\u0644\u0645\u062f\u062a \u0633\u06cc\u0634\u0646\u0632 \u06a9\u0627 \u0648\u0627\u062d\u062f \u067e\u0627\u0626\u06cc\u062f\u0627\u0631 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u0646\u06c1\u06cc\u06ba \u06c1\u0648\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<p>Redis \u06cc\u06c1\u0627\u06ba \u0688\u06cc\u0641\u0627\u0644\u0679 \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u06c1\u0645\u0627\u0631\u06d2 \u0645\u0639\u0627\u0645\u0644\u06d2 \u0645\u06cc\u06ba MongoDB \u0635\u0627\u0631\u0641\u060c \u0633\u06cc\u0634\u0646 \u0627\u0648\u0631 RefreshToken \u06a9\u0648 \u0627\u0633\u0679\u0648\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>Redis \u0634\u0631\u062d \u06a9\u0648 \u0645\u062d\u062f\u0648\u062f \u06a9\u0631\u0646\u06d2\u060c \u0639\u0627\u0631\u0636\u06cc \u06a9\u0627\u0624\u0646\u0679\u0631\u0632\u060c \u0645\u062e\u062a\u0635\u0631 \u0645\u062f\u062a \u06a9\u06d2 \u062a\u0627\u0644\u06d2\u060c OTP \u062d\u0627\u0644\u062a\u060c \u0639\u0627\u0631\u0636\u06cc \u062a\u0635\u062f\u06cc\u0642 \u06a9\u06cc \u062d\u0627\u0644\u062a\u060c \u0627\u0648\u0631 \u06a9\u06cc\u0634\u0646\u06af \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u0641\u06cc\u062f \u06c1\u06d2\u06d4<\/p>\n<p>\u06cc\u06c1 \u0627\u06cc\u06a9 \u0627\u06c1\u0645 \u062a\u0639\u0645\u06cc\u0631\u0627\u062a\u06cc \u0627\u0635\u0648\u0644 \u06c1\u06d2\u06d4 Redis \u06a9\u0648 \u0635\u0631\u0641 \u0627\u0633 \u0644\u06cc\u06d2 \u0634\u0627\u0645\u0644 \u0646\u06c1 \u06a9\u0631\u06cc\u06ba \u06a9\u06c1 \u0622\u067e \u06a9\u0627 \u067e\u0631\u0648\u0688\u06a9\u0634\u0646 \u0633\u0633\u0679\u0645 Redis \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0633\u06d2 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u06cc\u06ba \u062c\u06c1\u0627\u06ba \u0627\u0633 \u06a9\u06cc \u062e\u0635\u0648\u0635\u06cc\u0627\u062a \u0627\u06cc\u06a9 \u062d\u0642\u06cc\u0642\u06cc \u0645\u0633\u0626\u0644\u06c1 \u062d\u0644 \u06a9\u0631\u062a\u06cc \u06c1\u06cc\u06ba\u06d4<\/p>\n<h3 id=\"heading-rate-limiting\">\u0631\u0641\u062a\u0627\u0631 \u06a9\u06cc \u062d\u062f<\/h3>\n<p>\u0634\u0631\u062d \u06a9\u0648 \u0645\u062d\u062f\u0648\u062f \u06a9\u0631\u0646\u0627 \u0648\u0642\u062a \u06a9\u06cc \u0627\u06cc\u06a9 \u0645\u062f\u062a \u0645\u06cc\u06ba \u0628\u0627\u0631 \u0628\u0627\u0631 \u06a9\u06cc \u06a9\u0648\u0634\u0634\u0648\u06ba \u06a9\u0648 \u0645\u062d\u062f\u0648\u062f \u06a9\u0631\u06a9\u06d2 \u063a\u0644\u0637 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0648 \u06a9\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u062d\u062f\u0648\u06ba \u06a9\u0627 \u0627\u0646\u062a\u062e\u0627\u0628 \u0627\u062e\u062a\u062a\u0627\u0645\u06cc \u062e\u0637\u0631\u06d2 \u0627\u0648\u0631 \u0635\u0627\u0631\u0641 \u06a9\u06d2 \u062a\u062c\u0631\u0628\u06d2 \u06a9\u06cc \u0628\u0646\u06cc\u0627\u062f \u067e\u0631 \u06a9\u06cc\u0627 \u062c\u0627\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2 \u0627\u0648\u0631 \u0645\u0633\u062a\u0642\u0644 \u0646\u062a\u0627\u0626\u062c \u06a9\u06cc \u0648\u0627\u067e\u0633\u06cc \u06a9\u06cc \u062c\u0627\u0646\u06cc \u0686\u0627\u06c1\u06cc\u06d2\u06d4 <code>429 Too Many Requests<\/code> \u0627\u06af\u0631 \u06a9\u0644\u0627\u0626\u0646\u0679 \u0627\u0633 \u0633\u06d2 \u062a\u062c\u0627\u0648\u0632 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u062a\u0648 \u0648\u06c1 \u062c\u0648\u0627\u0628 \u062f\u06d2 \u06af\u0627\u06d4<\/p>\n<p>\u063a\u0648\u0631 \u06a9\u0631\u06cc\u06ba:<\/p>\n<pre><code class=\"language-text\">POST \/auth\/login\n<\/code><\/pre>\n<p>\u0627\u06cc\u06a9 \u062d\u0645\u0644\u06c1 \u0622\u0648\u0631 \u0645\u062e\u062a\u0635\u0631 \u0648\u0642\u062a \u0645\u06cc\u06ba 1000 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u0628\u06be\u06cc\u062c \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0622\u067e Redis \u06a9\u0627\u0624\u0646\u0679\u0631\u0632 \u06a9\u0648 \u0628\u0631\u0642\u0631\u0627\u0631 \u0631\u06a9\u06be \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-text\">auth:login:ip:<ip>\n<\/ip><\/code><\/pre>\n<p>\u0627\u0633 \u0645\u06cc\u06ba \u0645\u0646\u062f\u0631\u062c\u06c1 \u0630\u06cc\u0644 \u0627\u0636\u0627\u0641\u06c1 \u06a9\u0631\u06cc\u06ba:<\/p>\n<pre><code class=\"language-ts\">const attempts =\n  await redisService.increment(\n    key,\n    60,\n  );\n\nif (attempts > 10) {\n  throw new TooManyRequestsException();\n}\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u06a9\u0648\u0688 \u06a9\u06cc\u0627 \u06a9\u0631\u062a\u0627 \u06c1\u06d2: <code>key<\/code> \u0645\u0646\u062f\u0631\u062c\u06c1 \u0628\u0627\u0644\u0627 \u067e\u06cc\u0679\u0631\u0646 \u067e\u0631 \u0645\u0634\u062a\u0645\u0644 \u0627\u06cc\u06a9 \u06a9\u0627\u0624\u0646\u0679\u0631 \u06a9\u0627 \u0646\u0627\u0645\u060c \u062c\u06cc\u0633\u06d2 <code>auth:login:ip:203.0.113.7<\/code>)\u060c \u0644\u06c1\u0630\u0627 \u06c1\u0631 IP \u0627\u06cc\u0688\u0631\u06cc\u0633 \u06a9\u0627 \u0627\u067e\u0646\u0627 \u06a9\u0627\u0624\u0646\u0679\u0631 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4 <code>redisService.increment(key, 60)<\/code> \u0627\u06cc\u06a9 \u0645\u062f\u062f\u06af\u0627\u0631 \u062c\u0648 Redis \u0645\u06cc\u06ba \u0645\u062a\u0639\u0644\u0642\u06c1 \u06a9\u0627\u0624\u0646\u0679\u0631 \u0645\u06cc\u06ba 1 \u06a9\u0627 \u0627\u0636\u0627\u0641\u06c1 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0646\u0626\u06cc \u0642\u062f\u0631 \u0648\u0627\u067e\u0633 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u06a9\u06c1 <code>60<\/code> \u06a9\u06be\u0691\u06a9\u06cc \u06a9\u06cc \u0644\u0645\u0628\u0627\u0626\u06cc \u0633\u06cc\u06a9\u0646\u0688 \u0645\u06cc\u06ba\u06d4 \u062c\u0628 \u0627\u06cc\u06a9 \u06a9\u0644\u06cc\u062f \u067e\u06c1\u0644\u06cc \u0628\u0627\u0631 \u0628\u0646\u0627\u0626\u06cc \u062c\u0627\u062a\u06cc \u06c1\u06d2\u060c \u062a\u0648 \u0627\u0633 \u0645\u06cc\u06ba 60 \u0633\u06cc\u06a9\u0646\u0688 \u06a9\u0627 \u0679\u0627\u0626\u0645 \u0679\u0648 \u0644\u0627\u0626\u06cc\u0648 (TTL) \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u060c \u062c\u0633 \u06a9\u06d2 \u0628\u0639\u062f Redis \u062e\u0648\u062f \u0628\u062e\u0648\u062f \u06a9\u0644\u06cc\u062f \u06a9\u0648 \u062d\u0630\u0641 \u06a9\u0631 \u062f\u06cc\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u062f\u0648\u0628\u0627\u0631\u06c1 \u06af\u0646\u062a\u06cc \u0634\u0631\u0648\u0639 \u06c1\u0648 \u062c\u0627\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<p>\u06a9\u0648\u0688 \u067e\u06be\u0631 \u06af\u0646\u062a\u06cc \u06a9\u0627 \u062d\u062f \u0633\u06d2 \u0645\u0648\u0627\u0632\u0646\u06c1 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0633 \u0645\u062b\u0627\u0644 \u0645\u06cc\u06ba\u060c \u0627\u06af\u0631 \u06a9\u0633\u06cc IP \u0633\u06d2 60 \u0633\u06cc\u06a9\u0646\u0688 \u06a9\u06d2 \u0627\u0646\u062f\u0631 \u0627\u0646\u062f\u0631 10 \u0633\u06d2 \u0632\u06cc\u0627\u062f\u06c1 \u0644\u0627\u06af \u0627\u0646 \u06a9\u06cc \u06a9\u0648\u0634\u0634\u06cc\u06ba \u06c1\u0648\u062a\u06cc \u06c1\u06cc\u06ba\u060c \u062a\u0648 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0645\u0633\u062a\u0631\u062f \u06a9\u0631 \u062f\u06cc \u062c\u0627\u062a\u06cc \u06c1\u06d2\u06d4 <code>429 Too Many Requests<\/code> \u0622\u067e \u06a9\u06d2 \u067e\u0627\u0633 \u0648\u0631\u0688 \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2 \u0627\u06cc\u06a9 \u062e\u0631\u0627\u0628\u06cc \u067e\u06cc\u0634 \u0622 \u06af\u0626\u06cc\u06d4<\/p>\n<p>\u067e\u06c1\u0644\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u067e\u06cc\u062f\u0627 \u06a9\u0631\u062a\u06cc \u06c1\u06d2:<\/p>\n<pre><code class=\"language-text\">counter = 1\nTTL = 60 seconds\n<\/code><\/pre>\n<p>\u067e\u06be\u0631:<\/p>\n<pre><code class=\"language-text\">2\n3\n4\n...\n<\/code><\/pre>\n<p>Redis \u06a9\u0627 \u0627\u0634\u062a\u0631\u0627\u06a9 \u06a9\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2\u060c \u0644\u06c1\u0630\u0627 \u0646\u0645\u0628\u0631 \u0627\u06cc\u06a9 \u06c1\u06cc \u06c1\u06d2 \u0627\u0633 \u0633\u06d2 \u06a9\u0648\u0626\u06cc \u0641\u0631\u0642 \u0646\u06c1\u06cc\u06ba \u067e\u0691\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u06a9\u0648\u0646 \u0633\u06cc API \u0645\u062b\u0627\u0644 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u0648 \u06c1\u06cc\u0646\u0688\u0644 \u06a9\u0631\u062a\u06cc \u06c1\u06d2\u06d4 \u0628\u0631\u0627\u06c1 \u06a9\u0631\u0645 \u0627\u0633 \u06a9\u0627 \u062d\u0648\u0627\u0644\u06c1 \u062f\u06cc\u06ba\u06d4 <code>TooManyRequestsException<\/code> \u06cc\u06c1 \u067e\u0631\u0648\u0688\u06a9\u0634\u0646 \u0627\u0633\u0633\u0679\u0646\u0679 \u06c1\u06d2\u06d4 <code>429<\/code> \u062c\u0648\u0627\u0628 \u0627\u06af\u0631 \u0622\u067e \u06a9\u06d2 \u067e\u0631\u0648\u062c\u06cc\u06a9\u0679 \u0645\u06cc\u06ba \u06a9\u0648\u0626\u06cc \u0646\u06c1\u06cc\u06ba \u06c1\u06d2 \u062a\u0648\u060c \u0622\u067e \u067e\u06be\u06cc\u0646\u06a9 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba: <code>HttpException<\/code> \u062d\u06cc\u062b\u06cc\u062a \u06a9\u06d2 \u0633\u0627\u062a\u06be <code>429<\/code>.<\/p>\n<h3 id=\"heading-dont-rate-limit-only-by-ip\">\u0627\u067e\u0646\u06cc \u0631\u0641\u062a\u0627\u0631 \u06a9\u0648 \u0635\u0631\u0641 \u0627\u067e\u0646\u06d2 IP \u062a\u06a9 \u0645\u062d\u062f\u0648\u062f \u0646\u06c1 \u06a9\u0631\u06cc\u06ba\u06d4<\/h3>\n<p>\u0635\u0631\u0641 IP \u06a9\u06cc \u0634\u0631\u062d \u06a9\u0648 \u0645\u062d\u062f\u0648\u062f \u06a9\u0631\u0646\u0627 \u062c\u0627\u0626\u0632 \u0635\u0627\u0631\u0641\u06cc\u0646 \u06a9\u0648 \u0646\u0642\u0635\u0627\u0646 \u067e\u06c1\u0646\u0686\u0627 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0645\u062b\u0627\u0644 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631:<\/p>\n<pre><code class=\"language-text\">Company\n   \u2193\nNAT\n   \u2193\n100 users\n   \u2193\nsame public IP\n<\/code><\/pre>\n<p>\u0627\u06cc\u06a9 \u0628\u06c1\u062a\u0631 \u062d\u06a9\u0645\u062a \u0639\u0645\u0644\u06cc \u06cc\u06a9\u062c\u0627 \u06c1\u0648 \u0633\u06a9\u062a\u06cc \u06c1\u06d2:<\/p>\n<pre><code class=\"language-text\">IP\n+\nAccount identifier\n+\nIP + account\n<\/code><\/pre>\n<p>\u0645\u062b\u0627\u0644 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631:<\/p>\n<pre><code class=\"language-text\">auth:login:ip:<ip>\n\nauth:login:email:<hash>\n\nauth:login:ip-email:<ip>:<hash>\n<\/hash><\/ip><\/hash><\/ip><\/code><\/pre>\n<p>\u06c1\u0631 \u062c\u06c1\u062a \u067e\u0631 \u0645\u062e\u062a\u0644\u0641 \u067e\u0627\u0628\u0646\u062f\u06cc\u0627\u06ba \u0644\u0627\u06af\u0648 \u06c1\u0648 \u0633\u06a9\u062a\u06cc \u06c1\u06cc\u06ba\u06d4<\/p>\n<h3 id=\"heading-endpoints-worth-protecting\">\u062a\u062d\u0641\u0638 \u06a9\u06d2 \u0642\u0627\u0628\u0644 \u0627\u062e\u062a\u062a\u0627\u0645\u06cc \u0646\u06a9\u0627\u062a<\/h3>\n<p>\u062a\u0648\u062b\u06cc\u0642 \u0633\u06d2 \u0645\u062a\u0639\u0644\u0642\u06c1 \u0627\u062e\u062a\u062a\u0627\u0645\u06cc \u0646\u06a9\u0627\u062a \u067e\u0631 \u062e\u0635\u0648\u0635\u06cc \u062a\u0648\u062c\u06c1 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-text\">POST \/auth\/login\nPOST \/auth\/register\nPOST \/auth\/refresh\nPOST \/auth\/forgot-password\nPOST \/auth\/reset-password\nPOST \/auth\/verify-email\nPOST \/auth\/change-password\n<\/code><\/pre>\n<p>\u062e\u0627\u0635 \u0637\u0648\u0631 \u067e\u0631:<\/p>\n<pre><code class=\"language-text\">login\nrefresh\nforgot-password\n<\/code><\/pre>\n<p>\u06a9\u06cc\u0648\u0646\u06a9\u06c1 \u0648\u06c1 \u0628\u062f\u0633\u0644\u0648\u06a9\u06cc \u06a9\u06d2 \u0644\u06cc\u06d2 \u067e\u0631\u06a9\u0634\u0634 \u06c1\u062f\u0641 \u06c1\u06cc\u06ba\u06d4<\/p>\n<h2 id=\"heading-23-cors\">23. \u06a9\u0648\u0631\u0633<\/h2>\n<p>CORS \u0627\u06cc\u06a9 \u0628\u0631\u0627\u0624\u0632\u0631 \u067e\u0627\u0644\u06cc\u0633\u06cc \u06c1\u06d2 \u062c\u0648 \u06a9\u0646\u0679\u0631\u0648\u0644 \u06a9\u0631\u062a\u06cc \u06c1\u06d2 \u06a9\u06c1 \u06a9\u0648\u0646 \u0633\u06cc \u0627\u0635\u0644 \u06a9\u0631\u0627\u0633 \u0627\u0648\u0631\u06cc\u062c\u0646 \u062c\u0648\u0627\u0628\u0627\u062a \u067e\u0691\u06be \u0633\u06a9\u062a\u06cc \u06c1\u06d2\u06d4 \u06cc\u06c1 \u062a\u0648\u062b\u06cc\u0642 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2 \u0627\u0648\u0631 \u063a\u06cc\u0631 \u0628\u0631\u0627\u0624\u0632\u0631 \u06a9\u0644\u0627\u0626\u0646\u0679\u0633 \u06a9\u0648 API \u06a9\u0627\u0644 \u06a9\u0631\u0646\u06d2 \u0633\u06d2 \u0646\u06c1\u06cc\u06ba \u0631\u0648\u06a9\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u06cc\u06c1\u0627\u06ba \u062f\u0648 \u0627\u0635\u0637\u0644\u0627\u062d\u0627\u062a \u06a9\u06cc \u0648\u0636\u0627\u062d\u062a \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2\u06d4 \u0646\u06c1\u06cc\u06ba <em>\u067e\u06cc\u062f\u0627\u0626\u0634<\/em> \u06cc\u06c1 \u0627\u0633\u06a9\u06cc\u0645\u060c \u0645\u06cc\u0632\u0628\u0627\u0646 \u0627\u0648\u0631 \u0628\u0646\u062f\u0631\u06af\u0627\u06c1 \u06a9\u0627 \u0645\u062c\u0645\u0648\u0639\u06c1 \u06c1\u06d2\u06d4 <code>http:\/\/localhost:4200<\/code>. \u06a9\u0648\u0626\u06cc \u0631\u0627\u0633\u062a\u06c1 \u0646\u06c1\u06cc\u06ba <em>\u062a\u0635\u062f\u06cc\u0642 \u0634\u062f\u06c1 \u062f\u0631\u062e\u0648\u0627\u0633\u062a<\/em> \u0627\u06cc\u06a9 \u06a9\u0631\u0627\u0633 \u0627\u0648\u0631\u06cc\u062c\u0646 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u062c\u0633 \u0645\u06cc\u06ba \u0628\u0631\u0627\u0624\u0632\u0631 \u0645\u06cc\u06ba \u0627\u0633\u0646\u0627\u062f \u0634\u0627\u0645\u0644 \u06c1\u06cc\u06ba\u060c \u062c\u06cc\u0633\u06d2 \u06a9\u0648\u06a9\u06cc\u0632\u06d4 <code>withCredentials: true<\/code> \u06a9\u0631\u0648<\/p>\n<p>\u0627\u0633\u0646\u0627\u062f \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u06d2 \u0644\u06cc\u06d2\u060c \u0628\u0631\u0627\u0624\u0632\u0631 API \u06a9\u0648 \u0648\u0627\u0626\u0644\u0688 \u06a9\u0627\u0631\u0688 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2 \u0648\u0627\u0636\u062d \u0637\u0648\u0631 \u067e\u0631 \u0627\u062c\u0627\u0632\u062a \u06cc\u0627\u0641\u062a\u06c1 \u0627\u0635\u0644 (\u0641\u0631\u0646\u0679 \u0627\u06cc\u0646\u0688 \u0633\u06d2 \u0639\u06cc\u0646 \u0627\u0635\u0644) \u06a9\u0627 \u0646\u0627\u0645 \u062f\u06cc\u0646\u06d2 \u06a9\u0627 \u062a\u0642\u0627\u0636\u0627 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0648\u0627\u0626\u0644\u0688 \u06a9\u0627\u0631\u0688\u0632 \u06c1\u06cc\u06ba: <code>*<\/code>\u0627\u0633 \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 &quot;\u0622\u067e \u06cc\u06c1 \u06a9\u0633\u06cc \u0628\u06be\u06cc \u0630\u0631\u06cc\u0639\u06c1 \u0633\u06d2 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba&#8221; \u0627\u0648\u0631 \u0627\u06af\u0631 \u0627\u0633\u0646\u0627\u062f \u0634\u0627\u0645\u0644 \u06c1\u06cc\u06ba \u062a\u0648 \u0628\u0631\u0627\u0624\u0632\u0631 \u0627\u0633\u06d2 \u0642\u0628\u0648\u0644 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u06d2 \u06af\u0627\u06d4<\/p>\n<p>\u06a9\u0648\u0646\u06cc\u06cc \u0686\u0644 \u0633\u06a9\u062a\u0627 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-text\">http:\/\/localhost:4200\n<\/code><\/pre>\n<p>\u062c\u0628 NestJS \u0686\u0644 \u0631\u06c1\u0627 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-text\">http:\/\/localhost:3000\n<\/code><\/pre>\n<p>\u0686\u0648\u0646\u06a9\u06c1 \u0627\u0635\u0644\u06cc\u062a \u0645\u062e\u062a\u0644\u0641 \u06c1\u06cc\u06ba (\u0645\u062e\u062a\u0644\u0641 \u0628\u0646\u062f\u0631\u06af\u0627\u06c1\u06cc\u06ba)\u060c \u0628\u0631\u0627\u0624\u0632\u0631 CORS \u0642\u0648\u0627\u0646\u06cc\u0646 \u06a9\u0627 \u0627\u0637\u0644\u0627\u0642 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0622\u067e \u0627\u067e\u0646\u06d2 API \u06a9\u0648 \u0627\u0633 \u0637\u0631\u062d \u062a\u0631\u062a\u06cc\u0628 \u062f\u06d2 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-ts\">app.enableCors({\n  origin:\n    'http:\/\/localhost:4200',\n\n  credentials: true,\n});\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u062a\u0631\u062a\u06cc\u0628 \u062f\u0648 \u0686\u06cc\u0632\u06cc\u06ba \u06a9\u0631\u062a\u06cc \u06c1\u06d2: <code>origin<\/code> API \u06a9\u0648 \u0635\u0631\u0641 Angular \u0627\u06cc\u067e\u0633 \u0633\u06d2 \u06a9\u0631\u0627\u0633 \u0627\u0648\u0631\u06cc\u062c\u0646 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u0646\u06d2 \u06a9\u06cc \u06c1\u062f\u0627\u06cc\u062a \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 <code>http:\/\/localhost:4200<\/code>\u060c \u0644\u06c1\u0630\u0627 \u062c\u0648\u0627\u0628 \u0645\u06cc\u06ba \u0627\u06cc\u06a9 \u0645\u06cc\u0686 \u06c1\u0648\u06af\u0627\u06d4 <code>Access-Control-Allow-Origin<\/code> \u06c1\u06cc\u0688\u0631 <code>credentials: true<\/code> \u0634\u0627\u0645\u0644 \u06a9\u0631\u06cc\u06ba <code>Access-Control-Allow-Credentials: true<\/code>\u06cc\u06c1 \u0628\u0631\u0627\u0624\u0632\u0631 \u06a9\u0648 \u0627\u0633 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06d2 \u062c\u0648\u0627\u0628 \u0645\u06cc\u06ba \u06a9\u0648\u06a9\u06cc\u0632 (\u0645\u062b\u0644\u0627\u064b \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0648\u06a9\u06cc\u0632) \u0628\u06be\u06cc\u062c\u0646\u06d2 \u0627\u0648\u0631 \u0642\u0628\u0648\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u067e\u06cc\u062f\u0627\u0648\u0627\u0631 \u0645\u06cc\u06ba\u060c \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u0646\u06c1 \u06a9\u0631\u06cc\u06ba:<\/p>\n<pre><code class=\"language-ts\">origin: '*'\n<\/code><\/pre>\n<p>\u0627\u06cc\u06a9 \u0645\u0633\u062a\u0646\u062f \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06d2 \u0633\u0627\u062a\u06be\u06d4 \u0648\u0627\u0636\u062d\u060c \u0645\u0633\u062a\u0646\u062f \u0630\u0631\u0627\u0626\u0639 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<h2 id=\"heading-24-logout\">24. \u0644\u0627\u06af \u0622\u0624\u0679 \u06a9\u0631\u06cc\u06ba\u06d4<\/h2>\n<p>\u0644\u0627\u06af \u0622\u0624\u0679 \u06a9\u0631\u0646\u06d2 \u0633\u06d2 \u0645\u0648\u062c\u0648\u062f\u06c1 \u0633\u0631\u0648\u0631 \u0633\u0627\u0626\u06cc\u0688 \u0631\u06cc\u0641\u0631\u06cc\u0634\/\u0633\u06cc\u0634\u0646 \u06a9\u06cc \u062d\u0627\u0644\u062a \u06a9\u0648 \u0645\u0646\u0633\u0648\u062e \u06a9\u0631 \u062f\u06cc\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2 \u0627\u0648\u0631 \u0645\u0645\u0627\u062b\u0644 \u06a9\u0648\u06a9\u06cc \u0627\u0646\u062a\u0633\u0627\u0628 \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0648\u06a9\u06cc \u06a9\u0648 \u0635\u0627\u0641 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u06a9\u0648\u0646\u06cc\u06cc \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u0635\u0627\u0641 \u06a9\u0631\u0646\u06d2 \u0633\u06d2 \u0635\u0631\u0641 \u0645\u0648\u062c\u0648\u062f\u06c1 UI \u0644\u0627\u06af \u0622\u0624\u0679 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4 \u06cc\u06c1 \u0633\u0631\u0648\u0631 \u0633\u06d2 \u0686\u0648\u0631\u06cc \u0634\u062f\u06c1 \u0679\u0648\u06a9\u0646\u0632 \u06a9\u0648 \u0628\u0627\u0637\u0644 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0644\u0627\u06af \u0622\u0624\u0679 \u06a9\u0631\u0646\u06d2 \u0633\u06d2 \u0622\u067e \u06a9\u0627 \u0645\u0648\u062c\u0648\u062f\u06c1 \u0633\u06cc\u0634\u0646 \u0645\u0646\u0633\u0648\u062e \u06c1\u0648 \u062c\u0627\u0626\u06d2 \u06af\u0627\u06d4<\/p>\n<pre><code class=\"language-ts\">@Post('logout')\n@UseGuards(JwtAuthGuard)\nasync logout(\n  @Req() req: Request,\n  @Res({\n    passthrough: true,\n  })\n  res: Response,\n) {\n  await this.sessionsService\n    .revokeSession(\n      req.user.sessionId,\n    );\n\n  res.clearCookie(\n    'refresh_token',\n    {\n      httpOnly: true,\n      secure:\n        this.configService.get(\n          'NODE_ENV',\n        ) === 'production',\n      sameSite: 'strict',\n      path: '\/auth',\n    },\n  );\n\n  return {\n    message:\n      'Logged out successfully',\n  };\n}\n<\/code><\/pre>\n<p>\u06cc\u06c1\u0627\u06ba \u0627\u06cc\u06a9 \u0627\u06c1\u0645 \u0646\u06a9\u062a\u06c1 \u067e\u0631 \u062a\u0648\u062c\u06c1 \u062f\u06cc\u06ba\u06d4 \u0622\u067e \u06a9\u06cc \u0645\u0648\u062c\u0648\u062f\u06c1 \u0631\u0633\u0627\u0626\u06cc JWT \u062a\u06a9\u0646\u06cc\u06a9\u06cc \u0637\u0648\u0631 \u067e\u0631 \u0627\u0633 \u0648\u0642\u062a \u062a\u06a9 \u062f\u0631\u0633\u062a \u0631\u06c1 \u0633\u06a9\u062a\u06cc \u06c1\u06d2 \u062c\u0628 \u062a\u06a9 \u06a9\u06c1 \u0627\u0633 \u06a9\u06cc \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u0646\u06c1 \u06c1\u0648 \u062c\u0627\u0626\u06d2\u06d4 \u06cc\u06c1 \u062c\u0627\u0646 \u0628\u0648\u062c\u06be \u06a9\u0631 \u06a9\u06cc\u0627 \u06af\u06cc\u0627 \u0633\u0645\u062c\u06be\u0648\u062a\u06c1 \u06c1\u06d2\u06d4<\/p>\n<h3 id=\"heading-logout-all-devices\">\u062a\u0645\u0627\u0645 \u0622\u0644\u0627\u062a \u0633\u06d2 \u0633\u0627\u0626\u0646 \u0622\u0624\u0679 \u06a9\u0631\u06cc\u06ba\u06d4<\/h3>\n<p>\u0644\u0627\u06af \u0622\u0624\u0679 \u0633\u0628\u06be\u06cc \u06a9\u0648 \u0645\u0633\u062a\u0646\u062f \u0635\u0627\u0631\u0641 \u06a9\u06d2 \u0641\u0639\u0627\u0644 \u0633\u06cc\u0634\u0646 \u0627\u0648\u0631 \u0645\u062a\u0639\u0644\u0642\u06c1 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u0645\u0646\u0633\u0648\u062e \u06a9\u0631\u0646\u0627 \u06c1\u0648\u06af\u0627\u06d4 \u06cc\u0642\u06cc\u0646\u06cc \u0628\u0646\u0627\u0626\u06cc\u06ba \u06a9\u06c1 \u0635\u0627\u0631\u0641 ID \u062a\u0635\u062f\u06cc\u0642 \u0634\u062f\u06c1 \u062f\u0631\u062e\u0648\u0627\u0633\u062a ID \u0633\u06d2 \u0622\u062a\u06cc \u06c1\u06d2 \u0646\u06c1 \u06a9\u06c1 \u06a9\u0644\u0627\u0626\u0646\u0679 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06c1 \u062c\u0645\u0639 \u06a9\u0631\u0627\u0626\u06cc \u06af\u0626\u06cc \u0628\u06d2 \u062a\u0631\u062a\u06cc\u0628 ID \u0633\u06d2\u06d4<\/p>\n<p>\u06a9\u06cc\u0648\u0646\u06a9\u06c1 \u0627\u06cc\u06a9 \u0633\u06cc\u0634\u0646 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-text\">User\n \u251c\u2500\u2500 Session A\n \u251c\u2500\u2500 Session B\n \u2514\u2500\u2500 Session C\n<\/code><\/pre>\n<p>\u06c1\u0645 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-ts\">await sessionsService\n  .revokeAllUserSessions(\n    userId,\n  );\n<\/code><\/pre>\n<p>\u06cc\u06c1\u0627\u06ba \u06a9\u06cc\u0627 \u06c1\u0648 \u0631\u06c1\u0627 \u06c1\u06d2\u061f <code>revokeAllUserSessions<\/code> MongoDB \u0645\u06cc\u06ba \u0627\u0633 \u0635\u0627\u0631\u0641 \u0633\u06d2 \u062a\u0639\u0644\u0642 \u0631\u06a9\u06be\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u062a\u0645\u0627\u0645 \u0641\u0639\u0627\u0644 \u0633\u06cc\u0634\u0646\u0632 \u062a\u0644\u0627\u0634 \u06a9\u0631\u06cc\u06ba \u0627\u0648\u0631 \u06c1\u0631 \u0627\u06cc\u06a9 \u06a9\u0648 \u0645\u0646\u0633\u0648\u062e \u0634\u062f\u06c1 \u06a9\u06d2 \u0628\u0637\u0648\u0631 \u0646\u0634\u0627\u0646 \u0632\u062f \u06a9\u0631\u06cc\u06ba (\u0627\u0648\u0631 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u0645\u0646\u0633\u0648\u062e \u06a9\u0631\u06cc\u06ba)\u06d4 \u06a9\u06c1 <code>userId<\/code> \u0627\u06cc\u06a9 \u062a\u0635\u062f\u06cc\u0642 \u0634\u062f\u06c1 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0633\u06d2 \u0622\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2 (<code>req.user.userId<\/code>) \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06d2 \u062c\u0633\u0645 \u0645\u06cc\u06ba \u0638\u0627\u06c1\u0631 \u0646\u06c1\u06cc\u06ba \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u060c \u0644\u06c1\u0630\u0627 \u0635\u0627\u0631\u0641 \u0635\u0631\u0641 \u0627\u067e\u0646\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0644\u0627\u06af \u0622\u0624\u0679 \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 \u06cc\u06c1 &quot;\u06c1\u0631 \u062c\u06af\u06c1 \u0644\u0627\u06af \u0622\u0624\u0679&#8221; \u0628\u0679\u0646 \u06c1\u06d2 \u062c\u0633\u06d2 \u0622\u067e \u0628\u06c1\u062a \u0633\u06cc \u0627\u06cc\u067e\u0633 \u0645\u06cc\u06ba \u062f\u06cc\u06a9\u06be\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u0648\u0631 \u0627\u06af\u0631 \u0622\u067e \u0627\u067e\u0646\u0627 \u067e\u0627\u0633 \u0648\u0631\u0688 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631 \u0631\u06c1\u06d2 \u06c1\u06cc\u06ba \u06cc\u0627 \u0622\u067e \u06a9\u0648 \u06c1\u06cc\u06a9 \u06c1\u0648\u0646\u06d2 \u06a9\u0627 \u0634\u0628\u06c1 \u06c1\u06d2 \u062a\u0648 \u06cc\u06c1 \u0628\u06be\u06cc \u0645\u0641\u06cc\u062f \u06c1\u06d2\u06d4<\/p>\n<p>\u0646\u062a\u06cc\u062c\u06d2 \u06a9\u06cc \u0633\u0627\u062e\u062a \u06cc\u06c1 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-text\">Session A \nSession B \nSession C \n<\/code><\/pre>\n<p>\u0627\u0628 \u062a\u06cc\u0646\u0648\u06ba \u06a9\u0648 \u0645\u0646\u0633\u0648\u062e \u06a9\u0631 \u062f\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2\u06d4 \u06a9\u0633\u06cc \u0628\u06be\u06cc \u0645\u0633\u062a\u0642\u0628\u0644 \u06a9\u06cc \u062a\u0627\u0632\u06c1 \u06a9\u0627\u0631\u06cc \u06a9\u06cc \u06a9\u0648\u0634\u0634\u06cc\u06ba \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648 \u062c\u0627\u0626\u06cc\u06ba \u06af\u06cc\u060c \u0627\u0648\u0631 \u0645\u062e\u062a\u0635\u0631 \u0645\u062f\u062a \u062a\u06a9 \u0631\u0633\u0627\u0626\u06cc \u06a9\u06d2 \u0679\u0648\u06a9\u0646 \u06a9\u06cc \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648\u0646\u06d2 \u06a9\u06d2 \u0628\u0639\u062f \u062a\u0645\u0627\u0645 \u0622\u0644\u0627\u062a \u06a9\u0648 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0644\u0627\u06af \u0627\u0646 \u06a9\u0631\u0646\u0627 \u067e\u0691\u06d2 \u06af\u0627\u06d4<\/p>\n<h2 id=\"heading-25-mongodb-transaction-for-rotation\">25. \u06af\u0631\u062f\u0634 \u06a9\u06d2 \u0644\u06cc\u06d2 MongoDB \u0679\u0631\u0627\u0646\u0632\u06cc\u06a9\u0634\u0646<\/h2>\n<p>\u0627\u06af\u0631 \u0622\u067e \u0627\u06cc\u06a9 \u06c1\u06cc \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0622\u067e\u0631\u06cc\u0634\u0646 \u0645\u06cc\u06ba \u0645\u062a\u0639\u062f\u062f MongoDB \u062f\u0633\u062a\u0627\u0648\u06cc\u0632\u0627\u062a \u06a9\u0648 \u0627\u067e \u0688\u06cc\u0679 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u062a\u0648 \u0627\u0646 \u062a\u062d\u0631\u06cc\u0631\u0648\u06ba \u0645\u06cc\u06ba \u0645\u0633\u0644\u0633\u0644 \u0646\u0627\u06a9\u0627\u0645\u06cc \u06a9\u06d2 \u0631\u0648\u06cc\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4 MongoDB \u06a9\u062b\u06cc\u0631 \u062f\u0633\u062a\u0627\u0648\u06cc\u0632\u06cc \u0644\u06cc\u0646 \u062f\u06cc\u0646 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06cc\u0627 \u062a\u0648 \u0627\u06cc\u06a9 \u0631\u06cc\u067e\u0644\u06cc\u06a9\u0627 \u0633\u06cc\u0679 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2 (\u0628\u0634\u0645\u0648\u0644 \u0645\u0642\u0627\u0645\u06cc \u062a\u0631\u0642\u06cc \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u0645\u0646\u0627\u0633\u0628 \u0637\u0631\u06cc\u0642\u06d2 \u0633\u06d2 \u062a\u0634\u06a9\u06cc\u0644 \u0634\u062f\u06c1 \u0633\u0646\u06af\u0644 \u0646\u0648\u0688 \u0631\u06cc\u067e\u0644\u06cc\u06a9\u0627 \u0633\u06cc\u0679) \u06cc\u0627 \u0645\u0639\u0627\u0648\u0646 \u0634\u0627\u0631\u0688 \u062a\u0639\u06cc\u0646\u0627\u062a\u06cc \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4 \u06cc\u06c1 \u0627\u0633\u0679\u06cc\u0646\u0688 \u0627\u0633\u0679\u0648\u0646 MongoDB \u0633\u0631\u0648\u0631 \u067e\u0631 \u06a9\u0627\u0645 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u06d2 \u06af\u0627\u06d4<\/p>\n<p>\u0627\u06cc\u06a9 \u0627\u0648\u0631 \u067e\u06cc\u062f\u0627\u0648\u0627\u0631 \u067e\u0631 \u063a\u0648\u0631 \u06c1\u06d2\u06d4<\/p>\n<p>\u0641\u0631\u0636 \u06a9\u0631\u06cc\u06ba \u06a9\u06c1 \u06af\u0631\u062f\u0634 \u0645\u0646\u062f\u0631\u062c\u06c1 \u0630\u06cc\u0644 \u06a9\u0627\u0645 \u06a9\u0631\u062a\u06cc \u06c1\u06d2:<\/p>\n<pre><code class=\"language-text\">revoke R1\ncreate R2\n<\/code><\/pre>\n<p>\u0627\u06af\u0631 \u0627\u0646 \u06a9\u0627\u0631\u0631\u0648\u0627\u0626\u06cc\u0648\u06ba \u06a9\u06d2 \u062f\u0631\u0645\u06cc\u0627\u0646 \u0627\u06cc\u067e\u0644\u06cc\u06a9\u06cc\u0634\u0646 \u06a9\u0631\u06cc\u0634 \u06c1\u0648 \u062c\u0627\u0626\u06d2 \u062a\u0648 \u06a9\u06cc\u0627 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u061f<\/p>\n<p>\u06c1\u0645 \u062d\u0627\u0635\u0644 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-text\">R1 = revoked\nR2 = not created\n<\/code><\/pre>\n<p>\u0644\u06c1\u0630\u0627\u060c \u062c\u06c1\u0627\u06ba \u0645\u0646\u0627\u0633\u0628 \u06c1\u0648 \u0648\u06c1\u0627\u06ba MongoDB \u0644\u06cc\u0646 \u062f\u06cc\u0646 \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-text\">BEGIN\n   \u2193\nrevoke R1\n   \u2193\ncreate R2\n   \u2193\nupdate session\n   \u2193\nCOMMIT\n<\/code><\/pre>\n<p>\u0627\u06af\u0631 \u06a9\u0686\u06be \u063a\u0644\u0637 \u06c1\u0648 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u060c \u062a\u0648 \u0622\u067e \u06c1\u0645\u06cc\u0634\u06c1 \u067e\u06cc\u0686\u06be\u06d2 \u06c1\u0679 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u06cc\u06c1 \u06af\u0631\u062f\u0634 \u06a9\u0648 \u0627\u06cc\u0679\u0645 \u0635\u0631\u0641 \u0627\u0633 \u0635\u0648\u0631\u062a \u0645\u06cc\u06ba \u0628\u0646\u0627\u062a\u0627 \u06c1\u06d2 \u062c\u0628 \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u06a9\u06cc \u062a\u0639\u06cc\u0646\u0627\u062a\u06cc \u0644\u06cc\u0646 \u062f\u06cc\u0646 \u06a9\u06cc \u062d\u0645\u0627\u06cc\u062a \u06a9\u0631\u062a\u06cc \u06c1\u06d2 \u0627\u0648\u0631 \u062a\u0645\u0627\u0645 \u0645\u062a\u0639\u0644\u0642\u06c1 \u062a\u062d\u0631\u06cc\u0631\u06cc\u06ba \u0644\u06cc\u0646 \u062f\u06cc\u0646 \u0645\u06cc\u06ba \u0634\u0627\u0645\u0644 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>MongoDB \u06a9\u062b\u06cc\u0631 \u062f\u0633\u062a\u0627\u0648\u06cc\u0632\u06cc \u0644\u06cc\u0646 \u062f\u06cc\u0646 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06cc\u0627 \u062a\u0648 \u0627\u06cc\u06a9 \u0631\u06cc\u067e\u0644\u06cc\u06a9\u0627 \u0633\u06cc\u0679 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2 (\u0628\u0634\u0645\u0648\u0644 \u0645\u0642\u0627\u0645\u06cc \u062a\u0631\u0642\u06cc \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u0645\u0646\u0627\u0633\u0628 \u0637\u0631\u06cc\u0642\u06d2 \u0633\u06d2 \u062a\u0634\u06a9\u06cc\u0644 \u0634\u062f\u06c1 \u0633\u0646\u06af\u0644 \u0646\u0648\u0688 \u0631\u06cc\u067e\u0644\u06cc\u06a9\u0627 \u0633\u06cc\u0679) \u06cc\u0627 \u0645\u0639\u0627\u0648\u0646 \u0634\u0627\u0631\u0688 \u062a\u0639\u06cc\u0646\u0627\u062a\u06cc \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4 \u06cc\u06c1 \u0627\u0633\u0679\u06cc\u0646\u0688 \u0627\u0633\u0679\u0648\u0646 MongoDB \u0633\u0631\u0648\u0631 \u067e\u0631 \u06a9\u0627\u0645 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u06d2 \u06af\u0627\u06d4 \u0627\u0633 \u0628\u0627\u062a \u06a9\u0648 \u06cc\u0642\u06cc\u0646\u06cc \u0628\u0646\u0627\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u0634\u0631\u0648\u0637 \u0627\u067e \u0688\u06cc\u0679\u0633 \u0627\u0628\u06be\u06cc \u0628\u06be\u06cc \u062f\u0631\u06a9\u0627\u0631 \u06c1\u06cc\u06ba \u06a9\u06c1 \u0635\u0631\u0641 \u0627\u06cc\u06a9 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0645\u062e\u0635\u0648\u0635 \u0641\u0639\u0627\u0644 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<h2 id=\"heading-26-complete-authentication-flow\">26. \u062a\u0635\u062f\u06cc\u0642 \u06a9\u06d2 \u0628\u06c1\u0627\u0624 \u06a9\u0648 \u0645\u06a9\u0645\u0644 \u06a9\u0631\u06cc\u06ba\u06d4<\/h2>\n<p>\u0622\u0626\u06cc\u06d2 \u0633\u0628 \u06a9\u0686\u06be \u0627\u06cc\u06a9 \u0633\u0627\u062a\u06be \u0631\u06a9\u06be\u06cc\u06ba\u06d4 \u0645\u0646\u062f\u0631\u062c\u06c1 \u0630\u06cc\u0644 \u0630\u06cc\u0644\u06cc \u062d\u0635\u06d2 \u0627\u06cc\u06a9 \u0645\u0633\u062a\u0646\u062f \u0635\u0627\u0631\u0641 \u06a9\u06cc \u067e\u0648\u0631\u06cc \u0632\u0646\u062f\u06af\u06cc \u0645\u06cc\u06ba \u0642\u062f\u0645 \u0631\u06a9\u06be\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0628\u0634\u0645\u0648\u0644 \u0644\u0627\u06af \u0627\u0646 \u06a9\u0631\u0646\u0627\u060c \u0639\u0627\u0645 \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u06a9\u0631\u0646\u0627\u060c \u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u06c1\u0648\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u06c1\u06cc\u0646\u0688\u0644 \u06a9\u0631\u0646\u0627\u060c \u0627\u06af\u0631 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0686\u0648\u0631\u06cc \u06c1\u0648 \u062c\u0627\u0626\u06d2 \u062a\u0648 \u06a9\u06cc\u0627 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u062a\u0635\u062f\u06cc\u0642 \u06a9\u06d2 \u0641\u06cc\u0635\u0644\u06d2 \u06a9\u06cc\u0633\u06d2 \u06a9\u06cc\u06d2 \u062c\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<h3 id=\"heading-login\">\u0644\u0627\u06af \u0627\u0646<\/h3>\n<pre><code class=\"language-text\">Angular\n   \u2502\n   \u2502 email\/password\n   \u25bc\nNestJS\n   \u2502\n   \u251c\u2500\u2500 validate DTO\n   \u251c\u2500\u2500 rate limit\n   \u251c\u2500\u2500 find user\n   \u251c\u2500\u2500 bcrypt.compare\n   \u2502\n   \u251c\u2500\u2500 create session\n   \u251c\u2500\u2500 create R1\n   \u251c\u2500\u2500 store SHA-256(R1)\n   \u251c\u2500\u2500 create access JWT\n   \u2502\n   \u2514\u2500\u2500 Set-Cookie R1\n          \u2502\n          \u25bc\n       Angular\n       accessToken\n<\/code><\/pre>\n<h3 id=\"heading-normal-api-request\">\u0639\u0627\u0645 API \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba\u06d4<\/h3>\n<pre><code class=\"language-text\">Angular\n   \u2502\n   \u2502 Authorization: Bearer JWT\n   \u25bc\nNestJS\n   \u2502\n   \u25bc\nJwtAuthGuard\n   \u2502\n   \u25bc\nJWT validation\n   \u2502\n   \u25bc\nUser\n   \u2502\n   \u25bc\nRolesGuard\n   \u2502\n   \u25bc\nController\n   \u2502\n   \u25bc\nService\n<\/code><\/pre>\n<h3 id=\"heading-expired-access-token\">\u0645\u06cc\u0639\u0627\u062f \u062e\u062a\u0645 \u0634\u062f\u06c1 \u0631\u0633\u0627\u0626\u06cc \u0679\u0648\u06a9\u0646<\/h3>\n<pre><code class=\"language-text\">Angular\n   \u2502\n   \u25bc\nAPI\n   \u2502\n   \u25bc\n401\n   \u2502\n   \u25bc\nrefreshAccessToken()\n   \u2502\n   \u25bc\nPOST \/auth\/refresh\n   \u2502\n   \u2514\u2500\u2500 HttpOnly Cookie R1\n          \u2502\n          \u25bc\n      NestJS\n          \u2502\n          \u251c\u2500\u2500 hash R1\n          \u251c\u2500\u2500 find token\n          \u251c\u2500\u2500 check expiration\n          \u251c\u2500\u2500 check revoked\n          \u251c\u2500\u2500 check session\n          \u2502\n          \u251c\u2500\u2500 revoke R1\n          \u251c\u2500\u2500 create R2\n          \u2514\u2500\u2500 create new JWT\n                  \u2502\n                  \u25bc\n              Angular\n                  \u2502\n                  \u25bc\n             retry request\n<\/code><\/pre>\n<h3 id=\"heading-refresh-token-theft\">\u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0686\u0648\u0631\u06cc \u06c1\u0648 \u06af\u06cc\u0627\u06d4<\/h3>\n<p>\u0622\u0626\u06cc\u06d2 \u0641\u0631\u0636 \u06a9\u0631\u06cc\u06ba \u06a9\u06c1 \u062c\u0627\u0626\u0632 \u06a9\u0644\u0627\u0626\u0646\u0679 \u0627\u0648\u0631 \u062d\u0645\u0644\u06c1 \u0622\u0648\u0631 \u062f\u0648\u0646\u0648\u06ba \u06a9\u06d2 \u067e\u0627\u0633 \u0627\u06cc\u06a9 \u06c1\u06cc \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 R1 \u06c1\u06d2\u06d4 \u0627\u06cc\u0633\u0627 \u06c1\u0648 \u0633\u06a9\u062a\u0627 \u06c1\u06d2 \u0627\u06af\u0631 \u06a9\u0648\u0626\u06cc \u062d\u0645\u0644\u06c1 \u0622\u0648\u0631 \u0627\u0633\u06d2 \u06a9\u0633\u06cc \u06a9\u0645\u067e\u0631\u0648\u0645\u0627\u0626\u0632\u0688 \u0688\u06cc\u0648\u0627\u0626\u0633 \u0633\u06d2 \u06a9\u0627\u067e\u06cc \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u06cc\u0627 \u0627\u0633\u06d2 \u06a9\u0633\u06cc \u062c\u06af\u06c1 \u0631\u0648\u06a9\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u062c\u0627\u0626\u0632 \u06a9\u0644\u0627\u0626\u0646\u0679 \u067e\u06c1\u0644\u06d2 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0633\u0631\u0648\u0631 \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u06af\u06be\u0645\u0627\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-text\">Legitimate client:\nR1 \u2192 R2\n<\/code><\/pre>\n<p>R1 \u0627\u0628 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u0634\u062f\u06c1 \u0627\u0648\u0631 \u062a\u0628\u062f\u06cc\u0644 \u0634\u062f\u06c1 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u062f\u0631\u062c \u06c1\u06d2\u06d4 \u0628\u0639\u062f \u0645\u06cc\u06ba\u060c \u062d\u0645\u0644\u06c1 \u0622\u0648\u0631 \u0627\u0633 \u06a9\u0627\u067e\u06cc \u06a9\u0648 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u06a9\u0648\u0634\u0634 \u06a9\u0631\u06d2 \u06af\u0627\u06d4<\/p>\n<pre><code class=\"language-text\">R1\n<\/code><\/pre>\n<p>\u0633\u0631\u0648\u0631 R1 \u06a9\u0648 \u062f\u06cc\u06a9\u06be\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0633\u06d2 \u0688\u06be\u0648\u0646\u0688\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u062a\u0639\u06cc\u0646 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u06cc\u06c1 \u067e\u06c1\u0644\u06d2 \u06c1\u06cc \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06c1\u0648 \u0686\u06a9\u0627 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-text\">R1.revokedAt != null\n<\/code><\/pre>\n<p>\u0686\u0648\u0646\u06a9\u06c1 \u0627\u06cc\u06a9 \u062f\u0631\u0633\u062a \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0627\u06cc\u06a9 \u062f\u0631\u0633\u062a \u06a9\u0644\u0627\u0626\u0646\u0679 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06c1 \u06a9\u0628\u06be\u06cc \u0628\u06be\u06cc \u062f\u0648 \u0628\u0627\u0631 \u0646\u06c1\u06cc\u06ba \u062f\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0633 \u0644\u06cc\u06d2 \u0633\u0631\u0648\u0631 \u0627\u0633\u06d2 \u0627\u0633 \u0628\u0627\u062a \u06a9\u06cc \u0639\u0644\u0627\u0645\u062a \u0633\u0645\u062c\u06be\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u062f\u0648\u0646\u0648\u06ba \u0641\u0631\u06cc\u0642\u0648\u06ba \u06a9\u06d2 \u067e\u0627\u0633 \u0627\u06cc\u06a9 \u06c1\u06cc \u0679\u0648\u06a9\u0646 \u06c1\u06d2\u06d4 \u062d\u0645\u0644\u06c1 \u0622\u0648\u0631 \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u0648 \u0645\u062d\u0636 \u0645\u0633\u062a\u0631\u062f \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2\u060c \u06cc\u06c1 \u067e\u0648\u0631\u0627 \u0633\u06cc\u0634\u0646 \u062e\u062a\u0645 \u06a9\u0631\u06a9\u06d2 \u062c\u0648\u0627\u0628 \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-text\">Token reuse detected\n       \u2193\nRevoke session\n       \u2193\nForce re-authentication\n<\/code><\/pre>\n<p>\u0633\u06cc\u0634\u0646 \u06a9\u0648 \u0645\u0646\u0633\u0648\u062e \u06a9\u0631\u0646\u06d2 \u0633\u06d2 \u062c\u0627\u0626\u0632 \u0635\u0627\u0631\u0641 \u06a9\u06d2 \u067e\u0627\u0633 \u0645\u0648\u062c\u0648\u062f R2 \u0628\u06be\u06cc \u062e\u062a\u0645 \u06c1\u0648 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u060c \u0644\u06c1\u0630\u0627 \u062d\u0645\u0644\u06c1 \u0622\u0648\u0631 \u0635\u0631\u0641 \u0627\u0646\u062a\u0638\u0627\u0631 \u0646\u06c1\u06cc\u06ba \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u0627\u0648\u0631 \u062a\u0627\u0632\u06c1 \u062a\u0631\u06cc\u0646 \u0679\u0648\u06a9\u0646 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u0646\u06c1\u06cc\u06ba \u06a9\u0631 \u0633\u06a9\u062a\u0627\u06d4 \u062c\u0627\u0626\u0632 \u0635\u0627\u0631\u0641\u06cc\u0646 \u06a9\u0648 \u0644\u0627\u06af \u0622\u0624\u0679 \u0627\u0648\u0631 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0644\u0627\u06af \u0627\u0646 \u06a9\u0631\u0646\u0627 \u067e\u0691\u062a\u0627 \u06c1\u06d2\u060c \u062c\u0648 \u06a9\u06c1 \u062a\u06a9\u0644\u06cc\u0641 \u062f\u06c1 \u06c1\u06d2\u060c \u0644\u06cc\u06a9\u0646 \u062d\u0645\u0644\u06c1 \u0622\u0648\u0631 \u06a9\u0627 \u06a9\u0646\u06a9\u0634\u0646 \u062e\u062a\u0645 \u06a9\u0631 \u062f\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u062c\u0628 \u0635\u0627\u0631\u0641 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0644\u0627\u06af \u0627\u0646 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u060c \u062a\u0648 \u0627\u06cc\u06a9 \u0646\u0626\u06d2 \u0679\u0648\u06a9\u0646 \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 \u0627\u06cc\u06a9 \u0646\u06cc\u0627 \u0633\u06cc\u0634\u0646 \u0628\u0646\u0627\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2 \u062c\u0648 \u062d\u0645\u0644\u06c1 \u0622\u0648\u0631 \u06a9\u06d2 \u067e\u0627\u0633 \u0646\u06c1\u06cc\u06ba \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u062f\u0648\u0628\u0627\u0631\u06c1 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0627 \u067e\u062a\u06c1 \u0644\u06af\u0627\u0646\u0627 \u0635\u0631\u0641 \u0627\u0633 \u0635\u0648\u0631\u062a \u0645\u06cc\u06ba \u0645\u0641\u06cc\u062f \u06c1\u06d2 \u062c\u0628 \u0633\u0631\u0648\u0631 \u067e\u06c1\u0644\u06d2 \u0633\u06d2 \u0628\u062f\u0644\u06d2 \u06af\u0626\u06d2 \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u062f\u0631\u0633\u062a \u0645\u0648\u062c\u0648\u062f\u06c1 \u0679\u0648\u06a9\u0646 \u0633\u06d2 \u0645\u0645\u062a\u0627\u0632 \u06a9\u0631 \u0633\u06a9\u06d2 \u0627\u0648\u0631 \u0627\u06cc\u06a9 \u0645\u062a\u0639\u06cc\u0646 \u062c\u0648\u0627\u0628 \u06a9\u0627 \u0627\u0637\u0644\u0627\u0642 \u06a9\u0631 \u0633\u06a9\u06d2\u06d4 \u0627\u06af\u0631 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642 \u06c1\u0648 \u062c\u0627\u062a\u06cc \u06c1\u06d2 \u062a\u0648\u060c \u0645\u062a\u0627\u062b\u0631\u06c1 \u0633\u06cc\u0634\u0646 (\u06cc\u0627 \u0679\u0648\u06a9\u0646 \u0641\u06cc\u0645\u0644\u06cc) \u06a9\u0648 \u0645\u0646\u0633\u0648\u062e \u06a9\u0631 \u062f\u06cc\u0627 \u062c\u0627\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2 \u0627\u0648\u0631 \u0635\u0627\u0631\u0641 \u06a9\u0648 \u062f\u0648\u0628\u0627\u0631\u06c1 \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2\u06d4<\/p>\n<p>\u062a\u0644\u0627\u0634 \u06a9\u0631\u0646\u0627\u060c \u0645\u0648\u062c\u0648\u062f\u06c1 \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u0645\u0646\u0633\u0648\u062e \u06a9\u0631\u0646\u0627\u060c \u0645\u062a\u0628\u0627\u062f\u0644 \u0679\u0648\u06a9\u0646 \u0628\u0646\u0627\u0646\u0627\u060c \u0627\u0648\u0631 \u0633\u06cc\u0634\u0646\u0632 \u06a9\u0648 \u0627\u067e \u0688\u06cc\u0679 \u06a9\u0631\u0646\u0627 \u0627\u06cc\u0679\u0645 \u06c1\u0648\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u0628\u0635\u0648\u0631\u062a \u062f\u06cc\u06af\u0631\u060c \u06c1\u0645 \u0622\u06c1\u0646\u06af \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u06cc\u06ba \u062f\u0648\u0691 \u06a9\u06d2 \u062d\u0627\u0644\u0627\u062a \u06a9\u0627 \u0633\u0628\u0628 \u0628\u0646 \u0633\u06a9\u062a\u06cc \u06c1\u06cc\u06ba\u06d4 \u0645\u062d\u062a\u0627\u0637 \u0631\u06c1\u06cc\u06ba \u06a9\u06c1 \u062c\u0627\u0626\u0632 \u0645\u062a\u0648\u0627\u0632\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u067e\u0631 \u063a\u0648\u0631 \u06a9\u06cc\u06d2 \u0628\u063a\u06cc\u0631 \u06c1\u0631 \u0688\u067e\u0644\u06cc\u06a9\u06cc\u0679 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u0648 \u0686\u0648\u0631\u06cc \u0646\u06c1 \u0633\u0645\u062c\u06be\u06cc\u06ba \u06cc\u0627 \u062c\u0648\u0627\u0628\u06cc \u0646\u0642\u0635\u0627\u0646 \u06a9\u06d2 \u0628\u0639\u062f \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<h3 id=\"heading-authorization-flow\">\u0645\u0646\u0638\u0648\u0631\u06cc \u06a9\u0627 \u0628\u06c1\u0627\u0624<\/h3>\n<p>\u06a9\u06d2 \u0644\u06cc\u06d2:<\/p>\n<pre><code class=\"language-http\">DELETE \/users\/123\n<\/code><\/pre>\n<p>\u06c1\u0645 \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-text\">Request\n   \u2193\nAuthentication\n   \u2193\nuser = {\n   id: 123,\n   role: USER\n}\n   \u2193\nRolesGuard\n   \u2193\nRequired = ADMIN\n   \u2193\nUSER != ADMIN\n   \u2193\n403 Forbidden\n<\/code><\/pre>\n<h2 id=\"heading-27-security-review\">27. \u0633\u06cc\u06a9\u0648\u0631\u0679\u06cc \u06a9\u0627 \u062c\u0627\u0626\u0632\u06c1<\/h2>\n<p>\u0627\u0633\u06d2 \u062c\u0627\u0626\u0632\u06c1 \u0686\u06cc\u06a9 \u0644\u0633\u0679 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u06cc\u06ba\u060c \u0646\u06c1 \u06a9\u06c1 \u0627\u0633 \u0628\u0627\u062a \u06a9\u0627 \u062b\u0628\u0648\u062a \u06a9\u06c1 \u062a\u0645\u0627\u0645 \u06a9\u0646\u0679\u0631\u0648\u0644\u0632 \u0645\u06a9\u0645\u0644 \u0637\u0648\u0631 \u067e\u0631 \u0646\u0627\u0641\u0630 \u06c1\u0648 \u0686\u06a9\u06d2 \u06c1\u06cc\u06ba \u06cc\u0627 \u067e\u06cc\u062f\u0627\u0648\u0627\u0631 \u06a9\u06d2 \u0644\u06cc\u06d2 \u062a\u06cc\u0627\u0631 \u06c1\u06cc\u06ba\u06d4 \u06c1\u0631 \u0622\u0626\u0679\u0645 \u06a9\u0648 \u0627\u0635\u0644 \u06a9\u0648\u0688\u060c \u062a\u0639\u06cc\u0646\u0627\u062a\u06cc \u06a9\u06cc \u062a\u0631\u062a\u06cc\u0628\u0627\u062a\u060c \u0627\u0648\u0631 \u062e\u0648\u062f\u06a9\u0627\u0631 \u0679\u06cc\u0633\u0679 \u06a9\u06d2 \u062e\u0644\u0627\u0641 \u0686\u06cc\u06a9 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<h3 id=\"heading-passwords\">\u067e\u0627\u0633 \u0648\u0631\u0688<\/h3>\n<pre><code class=\"language-text\"> Password hashing\n No plaintext passwords\n Strong password policy\n<\/code><\/pre>\n<h3 id=\"heading-jwt\">\u062c\u06d2 \u0688\u0628\u0644\u06cc\u0648 \u0679\u06cc<\/h3>\n<pre><code class=\"language-text\"> Short-lived access tokens\n Strong secret\n Explicit algorithm\n Minimal payload\n<\/code><\/pre>\n<h3 id=\"heading-refresh-tokens\">\u0679\u0648\u06a9\u0646 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0631\u06cc\u06ba\u06d4<\/h3>\n<pre><code class=\"language-text\"> Cryptographically random\n SHA-256 hash at rest\n HttpOnly cookie\n Secure cookie in production\n SameSite policy\n Rotation\n Reuse detection\n<\/code><\/pre>\n<h3 id=\"heading-sessions\">\u0633\u06cc\u0634\u0646<\/h3>\n<pre><code class=\"language-text\"> Session per device\n Current-session logout\n Logout all\n Session revocation\n<\/code><\/pre>\n<h3 id=\"heading-authorization\">\u0627\u062c\u0627\u0632\u062a<\/h3>\n<pre><code class=\"language-text\"> JwtAuthGuard\n RolesGuard\n @Roles()\n 401 vs 403 separation\n<\/code><\/pre>\n<h3 id=\"heading-browser-security\">\u0628\u0631\u0627\u0624\u0632\u0631 \u0633\u06cc\u06a9\u0648\u0631\u0679\u06cc<\/h3>\n<pre><code class=\"language-text\"> CSRF protection\n CORS restrictions\n HttpOnly cookies\n<\/code><\/pre>\n<h3 id=\"heading-abuse-protection\">\u0628\u062f\u0633\u0644\u0648\u06a9\u06cc \u06a9\u06cc \u0631\u0648\u06a9 \u062a\u06be\u0627\u0645<\/h3>\n<pre><code class=\"language-text\"> Redis rate limiting\n Login protection\n Refresh protection\n<\/code><\/pre>\n<h3 id=\"heading-api-security\">API \u0633\u06cc\u06a9\u06cc\u0648\u0631\u0679\u06cc<\/h3>\n<pre><code class=\"language-text\"> DTO validation\n whitelist\n forbidNonWhitelisted\n Database constraints\n Explicit input mapping\n<\/code><\/pre>\n<h2 id=\"heading-28-things-we-should-add-later\">28. \u0628\u0639\u062f \u0645\u06cc\u06ba \u0634\u0627\u0645\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0686\u06cc\u0632\u06cc\u06ba<\/h2>\n<p>\u0627\u06cc\u06a9 \u062d\u0642\u06cc\u0642\u06cc \u067e\u0631\u0648\u0688\u06a9\u0634\u0646 \u0634\u0646\u0627\u062e\u062a\u06cc \u0646\u0638\u0627\u0645 \u06a9\u0648 \u0628\u0646\u06cc\u0627\u062f\u06cc \u0644\u0627\u06af \u0627\u0646 \u0627\u0648\u0631 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0641\u0644\u0648 \u0633\u06d2 \u0632\u06cc\u0627\u062f\u06c1 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4 \u0646\u06cc\u0686\u06d2 \u062f\u06cc\u06d2 \u06af\u0626\u06d2 \u0622\u0626\u0679\u0645\u0632 \u0627\u06cc\u0688 \u0622\u0646\u0632 \u06c1\u06cc\u06ba \u0627\u0648\u0631 \u0648\u06c1 \u0641\u06cc\u0686\u0631\u0632 \u0646\u06c1\u06cc\u06ba \u06c1\u06cc\u06ba \u062c\u0646 \u06a9\u06d2 \u0628\u0627\u0631\u06d2 \u0645\u06cc\u06ba \u0622\u067e \u06a9\u0648 \u0641\u0631\u0636 \u06a9\u0631 \u0644\u06cc\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2 \u062c\u0628 \u062a\u06a9 \u06a9\u06c1 \u0648\u06c1 \u0622\u067e \u06a9\u06cc \u0627\u06cc\u067e\u0644\u06cc\u06a9\u06cc\u0634\u0646 \u0645\u06cc\u06ba \u0644\u0627\u06af\u0648\u060c \u06a9\u0646\u0641\u06cc\u06af\u0631 \u0627\u0648\u0631 \u0679\u06cc\u0633\u0679 \u0646\u06c1 \u06c1\u0648\u06ba\u06d4<\/p>\n<h3 id=\"heading-email-verification\">\u0627\u067e\u0646\u0627 \u0627\u06cc \u0645\u06cc\u0644 \u0686\u06cc\u06a9 \u06a9\u0631\u06cc\u06ba\u06d4<\/h3>\n<pre><code class=\"language-text\">Register\n   \u2193\nVerification Email\n   \u2193\nVerify Token\n   \u2193\nemailVerified = true\n<\/code><\/pre>\n<h3 id=\"heading-password-reset\">\u067e\u0627\u0633 \u0648\u0631\u0688 \u062f\u0648\u0628\u0627\u0631\u06c1 \u062a\u0631\u062a\u06cc\u0628 \u062f\u06cc\u06ba\u06d4<\/h3>\n<pre><code class=\"language-text\">Forgot Password\n      \u2193\nReset Token\n      \u2193\nNew Password\n      \u2193\nRevoke existing sessions\n<\/code><\/pre>\n<h3 id=\"heading-mfa\">\u0627\u06cc\u0645 \u0627\u06cc\u0641 \u0627\u06d2<\/h3>\n<pre><code class=\"language-text\">Password\n   +\nAuthenticator \/ Passkey \/ OTP\n<\/code><\/pre>\n<h3 id=\"heading-security-events\">\u0633\u06cc\u06a9\u0648\u0631\u0679\u06cc \u0627\u06cc\u0648\u0646\u0679<\/h3>\n<p>\u0644\u0627\u06af:<\/p>\n<pre><code class=\"language-text\">Login success\nLogin failure\nLogout\nPassword change\nPassword reset\nRefresh reuse detection\nSession revoked\nRole changed\n<\/code><\/pre>\n<h3 id=\"heading-permission-based-authorization\">\u0627\u062c\u0627\u0632\u062a \u06a9\u06cc \u0628\u0646\u06cc\u0627\u062f \u067e\u0631 \u0645\u0646\u0638\u0648\u0631\u06cc<\/h3>\n<p>\u0628\u062c\u0627\u0626\u06d2:<\/p>\n<pre><code class=\"language-ts\">@Roles(UserRole.ADMIN)\n<\/code><\/pre>\n<p>\u06c1\u0645\u0627\u0631\u06d2 \u067e\u0627\u0633 \u0622\u062e\u0631 \u06a9\u0627\u0631 \u06cc\u06c1 \u06c1\u0648 \u0633\u06a9\u062a\u0627 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-ts\">@Permissions(\n  Permission.USERS_READ,\n  Permission.USERS_DELETE,\n)\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u067e\u06cc\u0686\u06cc\u062f\u06c1 \u0646\u0638\u0627\u0645\u0648\u06ba \u0633\u06d2 \u0628\u06c1\u062a\u0631 \u062a\u0631\u0627\u0632\u0648 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<h2 id=\"heading-29-the-most-important-architectural-lessons\">29. \u0641\u0646 \u062a\u0639\u0645\u06cc\u0631 \u06a9\u0627 \u0633\u0628 \u0633\u06d2 \u0627\u06c1\u0645 \u0633\u0628\u0642<\/h2>\n<p>\u0627\u0633 \u0646\u0638\u0627\u0645 \u0633\u06d2 \u0633\u0628 \u0633\u06d2 \u0628\u0691\u0627 \u0641\u0627\u0626\u062f\u06c1 \u0688\u06cc\u0632\u0627\u0626\u0646 \u06a9\u0627 \u0641\u06cc\u0635\u0644\u06c1 \u06c1\u06d2\u06d4<\/p>\n<h3 id=\"heading-lesson-1\">\u0633\u0628\u0642 1:<\/h3>\n<p>\u062a\u0635\u062f\u06cc\u0642 \u0627\u0648\u0631 \u0627\u062c\u0627\u0632\u062a \u0645\u062e\u062a\u0644\u0641 \u0645\u0633\u0627\u0626\u0644 \u06c1\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-text\">Authentication\nWho are you?\n\nAuthorization\nWhat can you do?\n<\/code><\/pre>\n<h3 id=\"heading-lesson-2\">\u0633\u0628\u0642 2:<\/h3>\n<p>\u0635\u0627\u0631\u0641\u06cc\u0646 \u0633\u06cc\u0634\u0646 \u0646\u06c1\u06cc\u06ba \u06c1\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-text\">User\n \u251c\u2500\u2500 Session A\n \u251c\u2500\u2500 Session B\n \u2514\u2500\u2500 Session C\n<\/code><\/pre>\n<h3 id=\"heading-lesson-3\">\u0633\u0628\u0642 3:<\/h3>\n<p>\u0636\u0631\u0648\u0631\u06cc \u0646\u06c1\u06cc\u06ba \u06a9\u06c1 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 JWT \u06c1\u0648\u06d4 \u0627\u06af\u0631 \u0633\u0631\u0648\u0631 \u067e\u06c1\u0644\u06d2 \u0633\u06d2 \u06c1\u06cc \u0633\u06cc\u0634\u0646 \u0627\u0633\u0679\u06cc\u0679 \u06a9\u0648 \u0627\u0633\u0679\u0648\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u062a\u0648 \u0628\u06d2 \u062a\u0631\u062a\u06cc\u0628 \u0645\u0628\u06c1\u0645 \u0679\u0648\u06a9\u0646 \u0622\u0633\u0627\u0646 \u0627\u0648\u0631 \u0645\u062d\u0641\u0648\u0638 \u06c1\u0648\u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<h3 id=\"heading-lesson-4\">\u0633\u0628\u0642 4:<\/h3>\n<p>\u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u06a9\u0648 \u0633\u0627\u062f\u06c1 \u0645\u062a\u0646 \u0645\u06cc\u06ba \u0630\u062e\u06cc\u0631\u06c1 \u0646\u06c1 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<p>\u0627\u0633\u06d2 \u0627\u0633 \u0637\u0631\u062d \u0645\u062d\u0641\u0648\u0638 \u06a9\u0631\u06cc\u06ba:<\/p>\n<pre><code class=\"language-text\">SHA256(refreshToken)\n<\/code><\/pre>\n<p>\u0627\u0633 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2.<\/p>\n<h3 id=\"heading-lesson-5\">\u0633\u0628\u0642 5:<\/h3>\n<p>\u0679\u0648\u06a9\u0646 \u06a9\u06cc \u06af\u0631\u062f\u0634 \u06a9\u0648 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u06a9\u0631\u0646\u06d2 \u0633\u06d2 \u0633\u06cc\u06a9\u06cc\u0648\u0631\u0679\u06cc \u0645\u0627\u0688\u0644 \u0628\u062f\u0644 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-text\">R1 \u2192 R2 \u2192 R3\n<\/code><\/pre>\n<p>\u062f\u0648\u0628\u0627\u0631\u06c1 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0627 \u067e\u062a\u06c1 \u0644\u06af\u0627\u06cc\u0627 \u062c\u0627 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<h3 id=\"heading-lesson-6\">\u0633\u0628\u0642 6:<\/h3>\n<p>\u0641\u0631\u0646\u0679 \u0627\u06cc\u0646\u0688 \u06af\u0627\u0631\u0688\u0632 \u062d\u0641\u0627\u0638\u062a\u06cc \u062d\u062f\u0648\u062f \u0646\u06c1\u06cc\u06ba \u06c1\u06cc\u06ba\u06d4 \u0628\u06cc\u06a9 \u0627\u06cc\u0646\u0688 \u06a9\u06cc \u0645\u0646\u0638\u0648\u0631\u06cc \u062f\u0631\u06a9\u0627\u0631 \u06c1\u06d2\u06d4<\/p>\n<h3 id=\"heading-lesson-7\">\u0633\u0628\u0642 7:<\/h3>\n<p>\u06a9\u0648\u06a9\u06cc\u0632 CSRF \u06a9\u06d2 \u062a\u062d\u0641\u0638\u0627\u062a \u0645\u062a\u0639\u0627\u0631\u0641 \u06a9\u0631\u0648\u0627\u062a\u06cc \u06c1\u06cc\u06ba\u06d4 HttpOnly JavaScript \u06a9\u0648 \u06a9\u0648\u06a9\u06cc\u0632 \u067e\u0691\u06be\u0646\u06d2 \u0633\u06d2 \u0631\u0648\u06a9\u062a\u0627 \u06c1\u06d2\u060c \u0644\u06cc\u06a9\u0646 \u062e\u0648\u062f CSRF \u06a9\u0648 \u062e\u062a\u0645 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<h3 id=\"heading-lesson-8\">\u0633\u0628\u0642 8:<\/h3>\n<p>\u0634\u0631\u062d \u06a9\u0648 \u0645\u062d\u062f\u0648\u062f \u06a9\u0631\u0646\u0627 \u062a\u0648\u062b\u06cc\u0642 \u06a9\u06cc \u062d\u0641\u0627\u0638\u062a \u06a9\u0627 \u062d\u0635\u06c1 \u06c1\u06d2\u06d4 \u0628\u0631\u0648\u0679 \u0641\u0648\u0631\u0633 \u067e\u0631\u0648\u0679\u06cc\u06a9\u0634\u0646 \u06a9\u06d2 \u0628\u063a\u06cc\u0631 \u0627\u06cc\u06a9 \u0645\u062d\u0641\u0648\u0638 \u067e\u0627\u0633 \u0648\u0631\u0688 \u0633\u0633\u0679\u0645 \u0646\u0627\u0645\u06a9\u0645\u0644 \u06c1\u06d2\u06d4<\/p>\n<h3 id=\"heading-lesson-9\">\u0633\u0628\u0642 9:<\/h3>\n<p>\u06c1\u0645 \u0622\u06c1\u0646\u06af\u06cc \u0633\u06cc\u06a9\u06cc\u0648\u0631\u0679\u06cc \u06a9\u0627 \u062d\u0635\u06c1 \u06c1\u06d2\u06d4 \u0631\u06cc\u0641\u0631\u06cc\u0634 \u0679\u0648\u06a9\u0646 \u0631\u0648\u0679\u06cc\u0634\u0646 \u0633\u0633\u0679\u0645 \u06a9\u0648 \u0645\u062a\u0639\u062f\u062f \u06c1\u0645 \u0622\u06c1\u0646\u06af\u06cc \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u0648\u06ba \u06a9\u0648 \u06c1\u06cc\u0646\u0688\u0644 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<h3 id=\"heading-lesson-10\">\u0633\u0628\u0642 10:<\/h3>\n<p>\u067e\u0631\u0648\u0688\u06a9\u0634\u0646 \u0633\u06cc\u06a9\u06cc\u0648\u0631\u0679\u06cc \u067e\u0631\u062a\u0648\u06ba \u067e\u0631 \u0645\u0634\u062a\u0645\u0644 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-text\">TLS\n \u2193\nCORS\n \u2193\nCSRF\n \u2193\nAuthentication\n \u2193\nAuthorization\n \u2193\nValidation\n \u2193\nRate Limiting\n \u2193\nDatabase Constraints\n \u2193\nSession Security\n \u2193\nMonitoring\n<\/code><\/pre>\n<p>\u06a9\u0648\u0626\u06cc \u0648\u0627\u062d\u062f \u0637\u0631\u06cc\u0642\u06c1 \u06a9\u0627\u0631 \u06a9\u0627\u0641\u06cc \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4<\/p>\n<h2 id=\"heading-30-final-architecture\">30. \u0641\u0627\u0626\u0646\u0644 \u0641\u0646 \u062a\u0639\u0645\u06cc\u0631<\/h2>\n<p>\u067e\u0648\u0631\u06d2 \u0646\u0638\u0627\u0645 \u06a9\u0648 \u0627\u0628 \u0627\u0633 \u0637\u0631\u062d \u062f\u06cc\u06a9\u06be\u0627 \u062c\u0627 \u0633\u06a9\u062a\u0627 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-text\">                         \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n                         \u2502    Angular    \u2502\n                         \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n                                 \u2502\n                    \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n                    \u2502                         \u2502\n             Access Token              Refresh Cookie\n                    \u2502                         \u2502\n             Memory only                  HttpOnly\n                    \u2502                         \u2502\n                    \u25bc                         \u25bc\n              Authorization              CSRF\n                 Header                 Protection\n                    \u2502                         \u2502\n                    \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n                                 \u2502\n                                 \u25bc\n                         \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n                         \u2502    NestJS     \u2502\n                         \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n                                 \u2502\n                 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n                 \u2502               \u2502               \u2502\n                 \u25bc               \u25bc               \u25bc\n          Rate Limiting    Authentication   Authorization\n             Redis          JWT Strategy      RolesGuard\n                 \u2502               \u2502               \u2502\n                 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n                                 \u2502\n                                 \u25bc\n                           Application\n                             Service\n                                 \u2502\n                       \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n                       \u25bc                   \u25bc\n                   MongoDB               Redis\n                       \u2502                   \u2502\n              \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510          \u2502\n              \u2502        \u2502        \u2502          \u2502\n             Users  Sessions Refresh    Rate Limits\n                            Tokens       Locks\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u0622\u067e \u06a9\u0648 \u0633\u06cc\u06a9\u0648\u0631\u0679\u06cc \u067e\u0631 \u0645\u0628\u0646\u06cc \u0641\u0646 \u062a\u0639\u0645\u06cc\u0631 \u0628\u0646\u0627\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4 \u067e\u06cc\u062f\u0627\u0648\u0627\u0631 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u0648\u0632\u0648\u06ba \u06c1\u0648\u0646\u06d2 \u06a9\u0627 \u0627\u0646\u062d\u0635\u0627\u0631 \u0646\u0641\u0627\u0630 \u06a9\u06cc \u067e\u062e\u062a\u06af\u06cc\u060c \u062a\u06be\u0631\u06cc\u0679 \u0645\u0627\u0688\u0644\u060c \u062a\u0639\u06cc\u0646\u0627\u062a\u06cc \u06a9\u06cc \u062a\u0631\u062a\u06cc\u0628\u060c \u0622\u067e\u0631\u06cc\u0634\u0646\u0644 \u0645\u0627\u0646\u06cc\u0679\u0631\u0646\u06af\u060c \u0627\u0648\u0631 \u0633\u06cc\u06a9\u06cc\u0648\u0631\u0679\u06cc \u0679\u06cc\u0633\u0679\u0646\u06af \u067e\u0631 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u062e\u0627\u06a9\u06c1 \u06a9\u0648 \u0630\u0645\u06c1 \u062f\u0627\u0631\u06cc\u0648\u06ba \u06a9\u06d2 \u0646\u0642\u0634\u06d2 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0627\u0633 \u0628\u0627\u062a \u06a9\u06cc \u0636\u0645\u0627\u0646\u062a \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2 \u0633\u0645\u062c\u06be\u06cc\u06ba \u06a9\u06c1 \u062a\u0645\u0627\u0645 \u06a9\u0646\u0679\u0631\u0648\u0644 \u067e\u06c1\u0644\u06d2 \u06c1\u06cc \u0646\u0627\u0641\u0630 \u06c1\u0648 \u0686\u06a9\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u0627\u06c1\u0645 \u0628\u0627\u062a \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u06c1\u0631 \u0645\u06cc\u06a9\u0627\u0646\u0632\u0645 \u06a9\u06cc \u0645\u062e\u0635\u0648\u0635 \u0630\u0645\u06c1 \u062f\u0627\u0631\u06cc\u0627\u06ba \u06c1\u0648\u062a\u06cc \u06c1\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-text\">JWT\n\u2192 short-lived authentication\n\nRefresh Token\n\u2192 session continuation\n\nSession\n\u2192 device\/session lifecycle\n\nRBAC\n\u2192 authorization\n\nCSRF\n\u2192 protection for cookie-based state-changing requests\n\nRedis\n\u2192 rate limiting and temporary\/distributed state\n\nMongoDB\n\u2192 persistent identity\/session data\n\nAngular Interceptor\n\u2192 client-side token lifecycle\n\nNestJS Guards\n\u2192 server-side security boundary\n<\/code><\/pre>\n<p>\u0627\u0646 \u0630\u0645\u06c1 \u062f\u0627\u0631\u06cc\u0648\u06ba \u06a9\u06cc \u0648\u0627\u0636\u062d \u0639\u0644\u06cc\u062d\u062f\u06af\u06cc \u0633\u0633\u0679\u0645 \u06a9\u06d2 \u0628\u0627\u0631\u06d2 \u0645\u06cc\u06ba \u0627\u0633\u062a\u062f\u0644\u0627\u0644\u060c \u062c\u0627\u0646\u0686\u060c \u067e\u06cc\u0645\u0627\u0646\u06c1 \u0627\u0648\u0631 \u0645\u062d\u0641\u0648\u0638 \u0628\u0646\u0627\u0646\u06d2 \u0645\u06cc\u06ba \u0628\u06c1\u062a \u0622\u0633\u0627\u0646 \u0628\u0646\u0627\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<h2 id=\"heading-explore-the-source-code\">\u0633\u0648\u0631\u0633 \u06a9\u0648\u0688 \u0646\u06cc\u0648\u06cc\u06af\u06cc\u0634\u0646<\/h2>\n<p>\u0622\u067e GitHub \u067e\u0631 \u0627\u0633 \u067e\u0631\u0648\u062c\u06cc\u06a9\u0679 \u06a9\u06d2 \u0633\u0648\u0631\u0633 \u06a9\u0648\u0688 \u06a9\u0648 \u062a\u0644\u0627\u0634 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p><strong>Angular \u0627\u0648\u0631 NestJS \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 \u062a\u0635\u062f\u06cc\u0642 \u0627\u0648\u0631 \u0627\u062c\u0627\u0632\u062a \u06a9\u0627 \u0646\u0638\u0627\u0645<\/strong><\/p>\n<p>\u0630\u062e\u06cc\u0631\u06c1 \u0627\u0633 \u0645\u0636\u0645\u0648\u0646 \u0645\u06cc\u06ba \u0632\u06cc\u0631 \u0628\u062d\u062b \u062a\u0635\u0648\u0631\u0627\u062a \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u0639\u0645\u0644\u06cc \u062d\u0648\u0627\u0644\u06c1 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0646\u0641\u0627\u0630\u0627\u062a \u06a9\u0648 \u062f\u0631\u06cc\u0627\u0641\u062a \u06a9\u0631\u0646\u06d2\u060c \u06a9\u0648\u0688 \u06a9\u0627 \u062c\u0627\u0626\u0632\u06c1 \u0644\u06cc\u0646\u06d2 \u0627\u0648\u0631 \u0641\u0646 \u062a\u0639\u0645\u06cc\u0631 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u062a\u062c\u0631\u0628\u06c1 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0622\u0632\u0627\u062f \u0645\u062d\u0633\u0648\u0633 \u06a9\u0631\u06cc\u06ba \u06a9\u06cc\u0648\u0646\u06a9\u06c1 \u0622\u067e \u06cc\u06c1 \u0633\u06cc\u06a9\u06be\u062a\u06d2 \u06c1\u06cc\u06ba \u06a9\u06c1 \u062c\u062f\u06cc\u062f \u0648\u06cc\u0628 \u0627\u06cc\u067e\u0644\u06cc\u06a9\u06cc\u0634\u0646\u0632 \u0645\u06cc\u06ba \u062a\u0635\u062f\u06cc\u0642 \u0627\u0648\u0631 \u0627\u062c\u0627\u0632\u062a \u0627\u06cc\u06a9 \u0633\u0627\u062a\u06be \u06a9\u06cc\u0633\u06d2 \u06a9\u0627\u0645 \u06a9\u0631\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<p>\u0627\u06af\u0631 \u0622\u067e \u06a9\u0648 \u06cc\u06c1 \u06a9\u0627\u0631\u0622\u0645\u062f \u0645\u0639\u0644\u0648\u0645 \u06c1\u0648\u0627\u060c \u062a\u0648 \u0628\u0631\u0627\u06c1 \u06a9\u0631\u0645 GitHub \u067e\u0631 \u0630\u062e\u06cc\u0631\u06d2 \u06a9\u0648 \u0633\u062a\u0627\u0631\u06c1 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u062a\u0648\u062b\u06cc\u0642 \u0627\u0646 \u0645\u0648\u0636\u0648\u0639\u0627\u062a \u0645\u06cc\u06ba \u0633\u06d2 \u0627\u06cc\u06a9 \u06c1\u06d2 \u062c\u0648 \u0622\u0633\u0627\u0646 \u0644\u06af\u062a\u0627 \u06c1\u06d2\u06d4 \u0635\u0627\u0631\u0641 \u0635\u0627\u0631\u0641 \u0646\u0627\u0645 \u0627\u0648\u0631 \u067e\u0627\u0633 \u0648\u0631\u0688 \u062c\u0645\u0639 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0633\u0631\u0648\u0631 \u0627\u0633\u0646\u0627\u062f \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0627\u06cc\u06a9 \u0679\u0648\u06a9\u0646 \u0648\u0627\u067e\u0633 \u06a9\u0631\u062a\u06cc \u06c1\u06d2\u06d4 \u062a\u0627\u06c1\u0645\u060c \u0627\u06cc\u06a9 \u0645\u062d\u0641\u0648\u0638 \u062a\u0635\u062f\u06cc\u0642\u06cc \u0646\u0638\u0627\u0645 \u0645\u06cc\u06ba JSON \u0648\u06cc\u0628 \u0679\u0648\u06a9\u0646 (JWT) \u0628\u0646\u0627\u0646\u06d2 \u0633\u06d2 \u0632\u06cc\u0627\u062f\u06c1 \u0634\u0627\u0645\u0644 \u06c1\u06d2\u06d4 \u0622\u067e \u06a9\u0648 \u067e\u0627\u0633 \u0648\u0631\u0688 \u0627\u0633\u0679\u0648\u0631\u06cc\u062c\u060c \u0631\u0633\u0627\u0626\u06cc \u0627\u0648\u0631 [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-33222","post","type-post","status-publish","format-standard","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/posts\/33222","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/comments?post=33222"}],"version-history":[{"count":0,"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/posts\/33222\/revisions"}],"wp:attachment":[{"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/media?parent=33222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/categories?post=33222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/tags?post=33222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}