{"id":7306,"date":"2026-08-05T08:58:02","date_gmt":"2026-08-04T23:58:02","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=7306"},"modified":"2026-08-05T16:15:00","modified_gmt":"2026-08-05T07:15:00","slug":"nextjs-social-login","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2026\/08\/05\/nextjs-social-login\/","title":{"rendered":"[nextjs]\uc18c\uc15c\ub85c\uadf8\uc778 \/ Social Login (github)"},"content":{"rendered":"\n<p>\ud83d\udc49\ud83c\udffb \uc544\ub798\uc758 \uc124\uba85\uc740 \uae43\ud5c8\ube0c \uc6f9\uc0ac\uc774\ud2b8 \uac00\uc785\uc815\ubcf4\ub97c \uc774\uc6a9\ud574\uc11c \uc18c\uc15c\ub85c\uadf8\uc778\uc744 \uad6c\ud604\ud558\ub294 \uc124\uba85\uc785\ub2c8\ub2e4.<br>The following explanation describes how to implement social login using GitHub account credentials.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb next-auth \ud328\ud0a4\uc9c0\ub85c \uac04\ub2e8\ud788 \uc18c\uc15c \ub85c\uadf8\uc778\uc744 \uad6c\ud604\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>You can easily implement social login using the next-auth package.<\/p>\n\n\n\n<p>\ud83d\udcc1 \uc804\uccb4 \ub514\ub809\ud1a0\ub9ac \uad6c\uc870<br>Overall directory structure<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>myapp5\/                        \n\u251c\u2500\u2500 <strong>.env.local <\/strong>                  # GitHub ID, Secret,AUTH_SECRET\n\u251c\u2500\u2500 <strong>auth.ts  <\/strong>                    # Auth.ts for github \n\u251c\u2500\u2500 package.json                 \n\u251c\u2500\u2500 tsconfig.json                \n\u2502\n\u2514\u2500\u2500 app\/                         \n    \u251c\u2500\u2500 layout.tsx              \n    \u251c\u2500\u2500 globals.css              \n    \u251c\u2500\u2500 page.tsx                 # Main Page(http:\/\/localhost:3000)\n    \u2502\n    \u251c\u2500\u2500 <strong>api\/ <\/strong>                    # Back-end\n    \u2502   \u2514\u2500\u2500 <strong>auth\/ <\/strong>               # auth\n    \u2502       \u2514\u2500\u2500 <strong>&#91;...nextauth]\/<\/strong>   # Catch-all\n    \u2502             \u2514\u2500\u2500 <strong>route.ts <\/strong>  # GET, POST handlers\n    \u2502\n    \u2514\u2500\u2500 <strong>socialauth\/ <\/strong>             \n        \u2514\u2500\u2500 <strong>page.tsx <\/strong>            # Login\n\n(http:\/\/localhost:3000\/socialauth)\n<\/code><\/pre>\n\n\n\n<p>\ud83d\udcc1 \ud504\ub85c\uc81d\ud2b8\uc124\uce58 \/ Project Installation<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npx create-next-app@latest<\/code><\/pre>\n\n\n\n<p>\ud83d\udcc1 NextAuth \ud328\ud0a4\uc9c0 \uc124\uce58<br>Install the NextAuth package<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm install next-auth@beta<\/code><\/pre>\n\n\n\n<p>\ud83d\udcc1 \uae43\ud5c8\ube0c\uc5d0 \uc571\ub4f1\ub85d<br>Register app on GitHub<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/settings\/developers\">https:\/\/github.com\/settings\/developers<\/a><\/p>\n\n\n\n<p>&#8212; \uae43\ud5c8\ube0c \ud398\uc774\uc9c0\uc5d0 \uc544\ub798\uc640 \uac19\uc774 \ub3d9\uc77c\ud558\uac8c \uc8fc\uc18c\ub97c \uc785\ub825\ud569\ub2c8\ub2e4.<br>Enter the address on the GitHub Pages site exactly as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Homepage URL: http:\/\/localhost:3000\nAuthorization callback URL: http:\/\/localhost:3000\/api\/auth\/callback\/github<\/code><\/pre>\n\n\n\n<p>1)ClientID\uc640 Client Secret\uc744 \uc800\uc7a5\ud574 \ub461\ub2c8\ub2e4.(1\ud68c\ub9cc \ub178\ucd9c)<br>Save the Client ID and Client Secret (they are displayed only once).<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"904\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/github_auth-2-jpg.jpg\" alt=\"\" class=\"wp-image-7371\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/github_auth-2-jpg.jpg 800w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/github_auth-2-jpg-265x300.jpg 265w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/github_auth-2-jpg-768x868.jpg 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/github_auth-2-jpg-400x452.jpg 400w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><figcaption class=\"wp-element-caption\">github-myapp5<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"659\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/github_auth-4-jpg.jpg\" alt=\"\" class=\"wp-image-7373\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/github_auth-4-jpg.jpg 800w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/github_auth-4-jpg-300x247.jpg 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/github_auth-4-jpg-768x633.jpg 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/github_auth-4-jpg-400x330.jpg 400w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><figcaption class=\"wp-element-caption\">github-myapp5<\/figcaption><\/figure>\n\n\n\n<p>\ud83d\udcc1 auth.ts\ud30c\uc77c \uc0dd\uc131<br>Create the auth.ts file.<\/p>\n\n\n\n<p>&#8212; project\/app\/auth.ts<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ auth.ts\nimport NextAuth from \"next-auth\"\nimport GitHub from \"next-auth\/providers\/github\"\n\nexport const { handlers, auth, signIn, signOut } = NextAuth({\n  providers: &#91;\n    GitHub({\n      clientId: process.env.AUTH_GITHUB_ID,\n      clientSecret: process.env.AUTH_GITHUB_SECRET,\n    }),\n  ],\n})<\/code><\/pre>\n\n\n\n<p>\ud83d\udcc1 \ud658\uacbd\ubcc0\uc218 \ud30c\uc77c \uc0dd\uc131(.env.local)<br>Create environment variable file (.env.local)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># .env.local\nAUTH_SECRET=\"\ub79c\ub364 \ubb38\uc790\uc5f4 \ud0a4\/Random string key\"\nAUTH_GITHUB_ID=\"\uae43\ud5c8\ube0c\uc5d0\uc11c \ubc1c\uae09\ubc1b\uc740 Client ID\/Client ID issued by GitHub\"\nAUTH_GITHUB_SECRET=\"\uae43\ud5c8\ube0c\uc5d0\uc11c \ubc1c\uae09\ubc1b\uc740 Client Secret\/Client Secret issued by GitHub\"<\/code><\/pre>\n\n\n\n<p>1)AUTH_SECRET<\/p>\n\n\n\n<p>\ud130\ubbf8\ub110\uc5d0 npx auth secret\uc744 \uc785\ub825\ud558\uba74 \ubb34\uc791\uc704 \ubb38\uc790\uc5f4\uc774 \uc790\ub3d9 \uc0dd\uc131\ub429\ub2c8\ub2e4.<br>Entering <code>npx auth secret<\/code> in the terminal automatically generates a random string.<\/p>\n\n\n\n<p>2)\uc0dd\uc131\ub41c \ubb38\uc790\uc5f4\uc744 AUTH_SECRET\uc5d0 \ubd99\uc5ec \ub123\uc2b5\ub2c8\ub2e4.<br>Paste the generated string into AUTH_SECRET.<\/p>\n\n\n\n<p>\ud83d\udcc1 API\ub77c\uc6b0\ud130 \ud578\ub4e4\ub7ec \uc791\uc131<br>Writing API Router Handlers<\/p>\n\n\n\n<p>&#8212; route.ts<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ app\/api\/auth\/&#91;...nextauth]\/route.ts\n\/\/import { handlers } from \"@\/auth\" \nimport { handlers } from \"..\/..\/..\/auth\" \nexport const { GET, POST } = handlers<\/code><\/pre>\n\n\n\n<p>1)route.ts \ud30c\uc77c\uc758 \uc704\uce58\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4. app\/api\/auth\/[&#8230;nextauth]\/route.ts<br>The location of the route.ts file is as follows: app\/api\/auth\/[\u2026nextauth]\/route.ts<\/p>\n\n\n\n<p>2)\uae43\ud5c8\ube0c\uc778\uc99d\uc2dc \ucf5c\ubc31 url\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<br>The callback URL for GitHub authentication is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><a href=\"http:\/\/localhost:3000\/api\/auth\/callback\/github\">http:\/\/localhost:3000\/api\/auth\/callback\/github<\/a><\/code><\/pre>\n\n\n\n<p>3) \ucf5c\ubc31 url\uc744 \ud1b5\ud574\uc11c \ubc1c\uae09\ubc1b\uc740 \ud0a4\ub97c \ud655\uc778\ud558\uac8c \ub429\ub2c8\ub2e4.<br>You will verify the issued key via the callback URL.<\/p>\n\n\n\n<p>4)\uc774 \ub54c [&#8230;nextauth] \uc544\ub798\uc5d0 route.ts\ub97c \ub9cc\ub4e4\uc5b4 \ub450\uba74 \/api\/auth \ub85c\ub4e4\uc5b4\uc624\ub294 \uc694\uccad\uc740 \ubaa8\ub450 route.ts\uc5d0\uc11c \ucc98\ub9ac\ud558\uac8c\ub429\ub2c8\ub2e4.<br>If you create a <code>route.ts<\/code> file under <code>[...nextauth]<\/code>, all requests coming into <code>\/api\/auth<\/code> will be handled by that <code>route.ts<\/code> file.<\/p>\n\n\n\n<p>5)\ub9cc\uc57d\uc5d0 \uadf8\ub0e5 \/auth\/route.ts\ub85c \ud30c\uc77c\uc744 \ub9cc\ub4e4\uba74 <a href=\"http:\/\/localhost:3000\/api\/auth\/callback\/github\">\/callback\/github<\/a> \uc774 \ubd80\ubd99\uc744 \ucc98\ub9ac \ud560 \uc218 \uc5c6\uae30 \ub584\ubb38\uc5d0 404 \uc624\ub958\uac00 \ubc1c\uc0dd\ud569\ub2c8\ub2e4.<br>If you simply create a file named <code>\/auth\/route.ts<\/code>, a 404 error will occur because it cannot handle the <code>\/callback\/github<\/code> path.<\/p>\n\n\n\n<p>\ud83d\udcc1 \ub85c\uadf8\uc778 \ud398\uc774\uc9c0 \uad6c\ud604\ud558\uae30<br>Implementing a Login Page<\/p>\n\n\n\n<p>&#8212; app\/socialauth\/page.tsx<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ app\/guestbook\/page.tsx\n\/\/import { auth, signIn, signOut } from \"@\/auth\"\nimport { auth, signIn, signOut } from \"..\/auth\"\n\nexport default async function GuestbookPage() {\n  \/\/ \uc11c\ubc84\uc5d0\uc11c \uc720\uc800 \uc815\ubcf4 \ubc14\ub85c \uac00\uc838\uc624\uae30\n  \/\/ Get user information directly from the server\n  const session = await auth() \n\n  return (\n    &lt;div className=\"p-8\">\n      &lt;h1 className=\"text-2xl font-bold mb-4\">Social Auth&lt;\/h1>\n\n      {session?.user ? (\n        &lt;div>\n          &lt;div className=\"flex items-center gap-2 mb-4\">\n            {\/* eslint-disable-next-line @next\/next\/no-img-element *\/}\n            &lt;img src={session.user.image || \"\"} alt=\"\ud504\ub85c\ud544\" className=\"w-8 h-8 rounded-full\" \/>\n            &lt;p>\uc548\ub155\ud558\uc138\uc694(Hello), &lt;strong>{session.user.name}&lt;\/strong>\ub2d8!&lt;\/p>\n          &lt;\/div>\n\n          {\/* Social Auth \uc791\uc131 \ud3fc \uc704\uce58 \/ social auth form location   *\/}\n          &lt;textarea className=\"border p-2 w-full mb-2\" placeholder=\"\uae00\uc744 \ub0a8\uaca8\ubcf4\uc138\uc694.\" \/>\n\n          {\/* \ub85c\uadf8\uc544\uc6c3 \ubc84\ud2bc \/ logout button*\/}\n          &lt;form action={async () => {\n            'use server';\n            await signOut();\n          }}>\n            &lt;button className=\"bg-red-500 text-white px-3 py-1 rounded\">\ub85c\uadf8\uc544\uc6c3\/logout&lt;\/button>\n          &lt;\/form>\n        &lt;\/div>\n      ) : (\n        &lt;div>\n          &lt;p className=\"mb-4\">\uae00\uc744 \uc791\uc131\ud558\ub824\uba74 \ub85c\uadf8\uc778\uc774 \ud544\uc694\ud569\ub2c8\ub2e4. \/ You need to be logged in to write a message.&lt;\/p>\n          {\/* \ub85c\uadf8\uc778 \ubc84\ud2bc (\uc11c\ubc84 \uc561\uc158 \ud65c\uc6a9) *\/}\n          &lt;form action={async () => {\n            'use server';\n            await signIn(\"github\");\n          }}>\n            &lt;button className=\"bg-black text-white px-4 py-2 rounded\">GitHub\ub85c \ub85c\uadf8\uc778 \/ Sign in with GitHub&lt;\/button>\n          &lt;\/form>\n        &lt;\/div>\n      )}\n    &lt;\/div>\n  )\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"608\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/socilalauto-login-1024x608.png\" alt=\"\" class=\"wp-image-7367\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/socilalauto-login-1024x608.png 1024w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/socilalauto-login-300x178.png 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/socilalauto-login-768x456.png 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/socilalauto-login-400x237.png 400w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/socilalauto-login-800x475.png 800w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/socilalauto-login.png 1324w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"818\" height=\"784\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/socialauth-logout.png\" alt=\"\" class=\"wp-image-7369\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/socialauth-logout.png 818w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/socialauth-logout-300x288.png 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/socialauth-logout-768x736.png 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/socialauth-logout-400x383.png 400w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/08\/socialauth-logout-800x767.png 800w\" sizes=\"auto, (max-width: 818px) 100vw, 818px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udc49\ud83c\udffb \uc544\ub798\uc758 \uc124\uba85\uc740 \uae43\ud5c8\ube0c \uc6f9\uc0ac\uc774\ud2b8 \uac00\uc785\uc815\ubcf4\ub97c \uc774\uc6a9\ud574\uc11c \uc18c\uc15c\ub85c\uadf8\uc778\uc744 \uad6c\ud604\ud558\ub294 \uc124\uba85\uc785\ub2c8\ub2e4.The following explanation describes how to implement social login using GitHub account credentials. \ud83d\udc49\ud83c\udffb next-auth \ud328\ud0a4\uc9c0\ub85c \uac04\ub2e8\ud788 \uc18c\uc15c \ub85c\uadf8\uc778\uc744 \uad6c\ud604\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.You can easily implement social login using the next-auth package. \ud83d\udcc1 \uc804\uccb4 \ub514\ub809\ud1a0\ub9ac \uad6c\uc870Overall directory structure \ud83d\udcc1 \ud504\ub85c\uc81d\ud2b8\uc124\uce58 \/ Project Installation \ud83d\udcc1 NextAuth \ud328\ud0a4\uc9c0 \uc124\uce58Install [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27,1,7],"tags":[],"class_list":["post-7306","post","type-post","status-publish","format-standard","hentry","category-nextjs","category-uncategorized","category-website","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/7306","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=7306"}],"version-history":[{"count":44,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/7306\/revisions"}],"predecessor-version":[{"id":7374,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/7306\/revisions\/7374"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=7306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=7306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=7306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}