{"id":4197,"date":"2024-04-29T11:15:36","date_gmt":"2024-04-29T09:15:36","guid":{"rendered":"https:\/\/juannunezblasco.es\/autenticacion-nextjs\/"},"modified":"2024-05-08T20:48:33","modified_gmt":"2024-05-08T18:48:33","slug":"autenticacion-nextjs","status":"publish","type":"post","link":"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/","title":{"rendered":"Implementing Authentication in Next.js: A Step-by-Step Guide [REPO]"},"content":{"rendered":"\n<p>In today&#8217;s article, we will dive into the world of Next.js to understand how to implement authentication so we can securely connect to our API.<\/p>\n\n<p>Our goal is to establish a robust and secure system that protects our data and that of our users.<\/p>\n\n<figure class=\"wp-block-video\"><video controls=\"\" src=\"https:\/\/juannunezblasco.es\/content\/uploads\/2024\/04\/Grabacio&#x301;n-de-pantalla-2024-04-28-a-las-17.26.08.mov\"><\/video><\/figure>\n\n<p>To achieve this goal, we will start by implementing middleware. This middleware will act as a gatekeeper, protecting our routes and ensuring that only authenticated users have access to them. This is a crucial step to ensure that our app is only accessible to those who have permission to use it.<\/p>\n\n<p>Next, we will create the login and registration forms. These forms are the front door for our users, so it is essential that they provide a smooth and secure user experience. We&#8217;ll explain how to design these forms to ensure they are easy to use and meet our security needs.<\/p>\n\n<p>Finally, we will save an encrypted cookie in the user&#8217;s browser. This cookie will be the key that will allow our authenticated users to make API calls. Ensuring this cookie is properly encrypted is vital to maintaining the security of our users and our application.<\/p>\n\n<p>You can see the project deployed on Codesandbox and the public repo on GitHub:<\/p>\n\n<p><a href=\"https:\/\/codesandbox.io\/p\/github\/juannunezblasco\/next-auth\/main\">https:\/\/codesandbox.io\/p\/github\/juannunezblasco\/next-auth\/main<\/a><\/p>\n\n<p><a href=\"https:\/\/github.com\/juannunezblasco\/next-auth\">https:\/\/github.com\/juannunezblasco\/next-auth<\/a><\/p>\n\n<h2 id=\"como-configurar-autenticacion-con-next-js\">How to configure authentication with Next.js<\/h2>\n\n<h3 id=\"1-proteger-rutas\">1. Protect routes<\/h3>\n\n<pre class=\"wp-block-code lang-ts\"><code>\/\/ middleware.ts \nexport const config = {\n  matcher: &#91;'\/((?!api|_next\/static|_next\/image|assets|images|styles|icons|favicon.ico|sw.js).*)']\n}\n\nexport async function middleware (request: NextRequest) {\n\n  const cookie = request.cookies.get('accessToken')?.value ?? ''\n\n  const token = await decrypt(cookie);\n\n  if (!\/^\\\/auth\\\/\/.test(request.nextUrl.pathname) &amp;&amp; !token) {\n    console.log('redirecting to login')\n    return NextResponse.redirect(new URL('\/auth\/login', request.url))\n  }\n  \n  if (\/^\\\/auth\\\/\/.test(request.nextUrl.pathname) &amp;&amp; token) {\n    return NextResponse.redirect(new URL('\/', request.url))\n  }\n\n  return NextResponse.next()\n\n}<\/code><\/pre>\n\n<p>The code block above shows how middleware can be implemented in Next.js to protect application routes. In this case, the middleware checks if a cookie called &#8216;accessToken&#8217; exists in the user&#8217;s browser.<\/p>\n\n<p>If the cookie exists and is encrypted, the user can continue browsing the application. If the cookie does not exist or is not encrypted, the middleware redirects the user to the login page.<\/p>\n\n<p>This middleware also verifies that if a user is already authenticated (i.e. has a token), they cannot access authentication routes (such as login), redirecting them to the main page instead.<\/p>\n\n<h3 id=\"2-encriptacion-de-cookies\">2. Cookie Encryption<\/h3>\n\n<pre class=\"wp-block-code lang-ts\"><code>\/\/ middlewares\/auth\/token.ts\n'use server';\n\nimport { JWTPayload, SignJWT, jwtVerify } from \"jose\";\n\nconst COOKIE_SECRET_KEY = 'nPt1cx%VyphXrz8waX#2*KW%ZoCI1S8oymrv%78Mnr'; \/\/ Change this to your own secret key come from .env file\nconst key = new TextEncoder().encode(COOKIE_SECRET_KEY);\n\nexport async function encrypt(payload: JWTPayload, expires: Date) {\n\n  return await new SignJWT(payload)\n    .setProtectedHeader({ alg: \"HS256\" })\n    .setIssuedAt()\n    .setExpirationTime(new Date( expires ))\n    .sign(key);\n}\n\nexport async function decrypt(input: string): Promise&lt;JWTPayload | null&gt; {\n\n  try {\n    const { payload } = await jwtVerify(input, key, {\n      algorithms: &#91;\"HS256\"],\n    });\n    return payload;\n    \n  } catch (error) {\n    return null;\n  }\n}<\/code><\/pre>\n\n<p>This code block shows how to encrypt and decrypt a cookie in Next.js to keep user information secure. The <code>encrypt<\/code> method takes a payload and an expiration date as arguments, creates a new JWT, and signs it. The <code>decrypt<\/code> method takes an input string, verifies the JWT, and returns the payload if the verification is successful. On error, it returns null. The encryption key <code>COOKIE_SECRET_KEY<\/code> must be a secure and unique string.<\/p>\n\n<h3 id=\"3-formularios-validaciones-y-acciones\">3. Forms, validations and actions<\/h3>\n\n<pre class=\"wp-block-code lang-tsx\"><code>\/\/ modules\/auth\/components\/sign-in-form.tsx\n'use client'\n\nimport { useFormState } from \"react-dom\";\n\nimport { ButtonSubmit } from \"@\/modules\/common\/components\/molecules\/button-submit\";\nimport { signInAction } from \"..\/..\/actions\/sign-in\";\nimport { FalRightToBranket } from \"@\/assets\/icons\/fal-right-to branket\";\n\nexport const SignInForm = () =&gt; {\n\n  const &#91;state, formAction] = useFormState(signInAction, undefined); \n  \n  return (\n    &lt;form \n      id=\"sign-in-form\"\n      data-testid=\"sign-in-form\"\n      className=\"flex flex-col gap-4 w-80 max-w-full\"\n      action={formAction}\n    &gt;\n      &lt;div className='flex flex-col'&gt;\n        &lt;label htmlFor=\"email\"&gt;Email&lt;\/label&gt;\n        &lt;input \n          id=\"email\" \n          name=\"email\"\n          placeholder=\"Email\" \n        \/&gt;\n      &lt;\/div&gt;\n      {state?.errors?.email &amp;&amp; &lt;p&gt;{state.errors.email}&lt;\/p&gt;}\n      &lt;div className='flex flex-col'&gt;\n        &lt;label htmlFor=\"password\"&gt;Password&lt;\/label&gt;\n        &lt;input \n          id=\"password\" \n          name=\"password\"\n          type=\"password\" \n          placeholder=\"Password\"\n        \/&gt;  \n      &lt;\/div&gt;\n      {state?.errors?.password &amp;&amp; (\n        &lt;div&gt;\n          &lt;p&gt;Password must:&lt;\/p&gt;\n          &lt;ul&gt;\n            {state.errors.password.map((error) =&gt; (\n              &lt;li key={error}&gt;- {error}&lt;\/li&gt;\n            ))}\n          &lt;\/ul&gt;\n        &lt;\/div&gt;\n      )}\n      &lt;div className=\"mb-4 w-full flex justify-center\"&gt;\n        &lt;ButtonSubmit&gt;\n          &lt;FalRightToBranket className=\"w-5 h-auto mr-2\" \/&gt;\n          Login\n        &lt;\/ButtonSubmit&gt;\n      &lt;\/div&gt;\n    &lt;\/form&gt;\n  )\n}<\/code><\/pre>\n\n<p>The code block above represents a login form in Next.js. Use the <code>useFormState<\/code> hook to handle the form state and the <code>signInAction<\/code> login action. The form consists of two fields: Email and Password, each with its corresponding label and a space to show validation errors. Finally, there is a submit button to submit the form.<\/p>\n\n<pre class=\"wp-block-code lang-ts\"><code>\/\/ modules\/auth\/actions\/sign-in.ts\n'use server '\n\nimport { SigninFormSchema, SigninFormState } from \"..\/domain\/sign-in-form-schema\";\nimport { setAuthCookie } from \"..\/hooks\/use-set-cookie\";\n\nexport const signInAction = async (state: SigninFormState, formData: FormData) =&gt; {\n  \/\/ Validate form fields\n  const validatedFields = SigninFormSchema.safeParse({\n    email: formData.get('email'),\n    password: formData.get('password'),\n  })\n  \n  \/\/ If any form fields are invalid, return early\n  if (!validatedFields.success) {\n    return {\n      errors: validatedFields.error.flatten().fieldErrors,\n    }\n  }\n\n  \/\/ Call the provider or db to signin a user...\n\n  const tomorrow = new Date();\n  tomorrow.setDate(tomorrow.getDate() + 1);\n\n  \/\/ Use the `tomorrow` date in your code\n  setAuthCookie({\n    token: 'access-token', \/\/ This should be the token you get from the server\n    expiresAt: tomorrow\n  });\n\n}<\/code><\/pre>\n\n<p>The code block above shows how to handle the login action in Next.js. First, validate the form fields using a defined schema (<code>SigninFormSchema<\/code>). If any field is invalid, an object is returned with the corresponding validation errors.<\/p>\n\n<pre class=\"wp-block-code lang-ts\"><code>\/\/ modules\/auth\/domain\/sign-in-form-schema.ts\n\nimport { z } from 'zod'\n \nexport const SigninFormSchema = z.object({\n  email: z.string().email({ message: 'Please enter a valid email.' }).trim(),\n  password: z\n    .string()\n    .min(8, { message: 'Be at least 8 characters long' })\n    .regex(\/&#91;a-zA-Z]\/, { message: 'Contain at least one letter.' })\n    .regex(\/&#91;0-9]\/, { message: 'Contain at least one number.' })\n    .regex(\/&#91;^a-zA-Z0-9]\/, {\n      message: 'Contain at least one special character.',\n    })\n    .trim(),\n})\n \nexport type SigninFormState =\n  | {\n      errors?: {\n        email?: string&#91;]\n        password?: string&#91;]\n      }\n      message?: string\n    }\n  | undefined<\/code><\/pre>\n\n<p>If all fields are valid, a call is made to the provider or database to log in a user (this part of the code is not shown).<\/p>\n\n<p>Finally, an authentication cookie (<code>setAuthCookie<\/code>) is set with a token (in this example, a text string &#8216;access-token&#8217;, but in a real case, it would be the token that is obtained from the server) and a date of expiration (in the example, the day after the current one).<\/p>\n\n<pre class=\"wp-block-code lang-tsx\"><code>\/\/ modules\/auth\/hooks\/use-set-cookie.tsx\n'use server'\n\nimport { encrypt } from '@\/middlewares\/auth\/token';\nimport { cookies } from 'next\/headers';\nimport { redirect} from 'next\/navigation';\n\nexport const setAuthCookie = async (state: { token: string, expiresAt: Date }) =&gt; {\n\n  const encryptedToken = await encrypt( {\n    ...state\n  }, state.expiresAt )\n\n  cookies().set({\n    name: 'accessToken',\n    value: encryptedToken,\n    expires: state.expiresAt,\n    path: '\/',\n    sameSite: 'strict',\n    secure: process.env.NODE_ENV === 'production',\n  })\n\n  redirect('\/')\n\n}\n<\/code><\/pre>\n\n<p>The code block above shows how to set an authentication cookie in Next.js. First, encrypt the token and expiration date with the encrypt function. Then you set the cookie with the name &#8216;accessToken&#8217;, the encrypted token as value, the expiration date, the path &#8216;\/&#8217;, a strict &#8216;sameSite&#8217; policy, and a secure configuration if the environment is production. Finally, it redirects the user to the main page.<\/p>\n\n<h3 id=\"4-tests\">4. Tests<\/h3>\n\n<p>Basic configuration for testing with Jest and Testing Library.<\/p>\n\n<pre class=\"wp-block-code lang-tsx\"><code>\/\/ __tests__\/app\/auth\/login.test.txs\n\nimport { render, screen } from '@testing-library\/react'\nimport '@testing-library\/jest-dom'\nimport Login from '@\/app\/auth\/login\/page'\nimport { SignInForm } from '@\/modules\/auth\/components\/sign-in-form\/sign-in-form'\n \n\n\n\/\/ Mock the component you want to test if it's rendered\njest.mock('@\/modules\/auth\/components\/sign-in-form\/sign-in-form', () =&gt; {\n  return {\n    __esModule: true,\n    SignInForm: () =&gt; {\n      return &lt;div&gt;Mocked Component&lt;\/div&gt;\n    },\n  }\n})\n\ndescribe('Login page', () =&gt; {\n  it('renders a heading', () =&gt; {\n    render(&lt;Login \/&gt;)\n \n    const heading = screen.getByRole('heading', { level: 1 })\n \n    expect(heading).toBeInTheDocument()\n  })\n\n  it('renders the SignInForm component', () =&gt; {\n    render(&lt;Login \/&gt;)\n \n    const signInForm = screen.getByText('Mocked Component')\n \n    expect(signInForm).toBeInTheDocument()\n  })\n  \n})<\/code><\/pre>\n\n<p>The code block above corresponds to a set of unit tests for a login page in Next.js, using the Jest and Testing Library libraries.<\/p>\n\n<p>It starts by importing the necessary libraries and the component to be tested. <code>jest.mock<\/code> is then used to create a &#8216;mock&#8217; of the <code>SignInForm<\/code> component, which is rendered as a div with the text &#8216;Mocked Component&#8217;.<\/p>\n\n<p>The test suite contains two tests:<\/p>\n\n<ol><li>The first test verifies that the login page renders a header. To do this, render the <code>Login<\/code> component and then look for an element with the header role at level 1. If this element is in the document, the test passes.<\/li><li>The second test verifies that the <code>SignInForm<\/code> component is rendered on the login page. Render the component <code>Login<\/code> and then look for an element with the text &#8216;Mocked Component&#8217;. If this element is in the document, the test passes.<\/li><\/ol>\n\n<h2 id=\"conclusiones\">Conclusions<\/h2>\n\n<p>This article provides a basic example of how to implement authentication in Next.js. It ranges from protecting routes, encrypting cookies, creating login and registration forms, to performing tests.<\/p>\n\n<p>If it has been helpful to you, I encourage you to share it on your networks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In today&#8217;s article, we will dive into the world of Next.js to understand how to implement authentication so we can securely connect to our API. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4141,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[73,74],"tags":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v18.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Implementing Authentication in Next.js: A Step-by-Step Guide [REPO] | J - Desarrollo Aplicaciones Web<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Implementing Authentication in Next.js: A Step-by-Step Guide [REPO] | J - Desarrollo Aplicaciones Web\" \/>\n<meta property=\"og:description\" content=\"In today&#8217;s article, we will dive into the world of Next.js to understand how to implement authentication so we can securely connect to our API. [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/\" \/>\n<meta property=\"og:site_name\" content=\"J - Desarrollo Aplicaciones Web\" \/>\n<meta property=\"article:published_time\" content=\"2024-04-29T09:15:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-08T18:48:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/juannunezblasco.es\/content\/uploads\/2024\/04\/auth-next.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1260\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Juan N\u00fa\u00f1ez Blaco\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/juannunezblasco.es\/#organization\",\"name\":\"J - Desarrollo Aplicaciones Web\",\"url\":\"https:\/\/juannunezblasco.es\/\",\"sameAs\":[],\"logo\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/juannunezblasco.es\/#logo\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/juannunezblasco.local\/content\/uploads\/2022\/02\/logo-jnb-positivo.png\",\"contentUrl\":\"http:\/\/juannunezblasco.local\/content\/uploads\/2022\/02\/logo-jnb-positivo.png\",\"width\":512,\"height\":513,\"caption\":\"J - Desarrollo Aplicaciones Web\"},\"image\":{\"@id\":\"https:\/\/juannunezblasco.es\/#logo\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/juannunezblasco.es\/#website\",\"url\":\"https:\/\/juannunezblasco.es\/\",\"name\":\"J - Desarrollo Aplicaciones Web\",\"description\":\"Dise\u00f1o y desarrollos de productos digitales a medida\",\"publisher\":{\"@id\":\"https:\/\/juannunezblasco.es\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/juannunezblasco.es\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/juannunezblasco.es\/content\/uploads\/2024\/04\/auth-next.jpg\",\"contentUrl\":\"https:\/\/juannunezblasco.es\/content\/uploads\/2024\/04\/auth-next.jpg\",\"width\":1260,\"height\":630,\"caption\":\"Guide to implement authentication with Next.js\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/#webpage\",\"url\":\"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/\",\"name\":\"Implementing Authentication in Next.js: A Step-by-Step Guide [REPO] | J - Desarrollo Aplicaciones Web\",\"isPartOf\":{\"@id\":\"https:\/\/juannunezblasco.es\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/#primaryimage\"},\"datePublished\":\"2024-04-29T09:15:36+00:00\",\"dateModified\":\"2024-05-08T18:48:33+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/juannunezblasco.es\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Implementing Authentication in Next.js: A Step-by-Step Guide [REPO]\"}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/#webpage\"},\"author\":{\"@id\":\"https:\/\/juannunezblasco.es\/#\/schema\/person\/31582cd4a29af7055b4c3b0508601b29\"},\"headline\":\"Implementing Authentication in Next.js: A Step-by-Step Guide [REPO]\",\"datePublished\":\"2024-04-29T09:15:36+00:00\",\"dateModified\":\"2024-05-08T18:48:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/#webpage\"},\"wordCount\":838,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/juannunezblasco.es\/#organization\"},\"image\":{\"@id\":\"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/juannunezblasco.es\/content\/uploads\/2024\/04\/auth-next.jpg\",\"articleSection\":[\"Next.js\",\"React\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/#respond\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/juannunezblasco.es\/#\/schema\/person\/31582cd4a29af7055b4c3b0508601b29\",\"name\":\"Juan N\u00fa\u00f1ez Blaco\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/juannunezblasco.es\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/23b8417ac4b489153038755511de438e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/23b8417ac4b489153038755511de438e?s=96&d=mm&r=g\",\"caption\":\"Juan N\u00fa\u00f1ez Blaco\"},\"description\":\"Full Stack Developer\",\"sameAs\":[\"https:\/\/juannunezblasco.es\"],\"url\":\"https:\/\/juannunezblasco.es\/en\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Implementing Authentication in Next.js: A Step-by-Step Guide [REPO] | J - Desarrollo Aplicaciones Web","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/","og_locale":"en_US","og_type":"article","og_title":"Implementing Authentication in Next.js: A Step-by-Step Guide [REPO] | J - Desarrollo Aplicaciones Web","og_description":"In today&#8217;s article, we will dive into the world of Next.js to understand how to implement authentication so we can securely connect to our API. [&hellip;]","og_url":"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/","og_site_name":"J - Desarrollo Aplicaciones Web","article_published_time":"2024-04-29T09:15:36+00:00","article_modified_time":"2024-05-08T18:48:33+00:00","og_image":[{"width":1260,"height":630,"url":"https:\/\/juannunezblasco.es\/content\/uploads\/2024\/04\/auth-next.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Written by":"Juan N\u00fa\u00f1ez Blaco","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Organization","@id":"https:\/\/juannunezblasco.es\/#organization","name":"J - Desarrollo Aplicaciones Web","url":"https:\/\/juannunezblasco.es\/","sameAs":[],"logo":{"@type":"ImageObject","@id":"https:\/\/juannunezblasco.es\/#logo","inLanguage":"en-US","url":"http:\/\/juannunezblasco.local\/content\/uploads\/2022\/02\/logo-jnb-positivo.png","contentUrl":"http:\/\/juannunezblasco.local\/content\/uploads\/2022\/02\/logo-jnb-positivo.png","width":512,"height":513,"caption":"J - Desarrollo Aplicaciones Web"},"image":{"@id":"https:\/\/juannunezblasco.es\/#logo"}},{"@type":"WebSite","@id":"https:\/\/juannunezblasco.es\/#website","url":"https:\/\/juannunezblasco.es\/","name":"J - Desarrollo Aplicaciones Web","description":"Dise\u00f1o y desarrollos de productos digitales a medida","publisher":{"@id":"https:\/\/juannunezblasco.es\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/juannunezblasco.es\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/#primaryimage","inLanguage":"en-US","url":"https:\/\/juannunezblasco.es\/content\/uploads\/2024\/04\/auth-next.jpg","contentUrl":"https:\/\/juannunezblasco.es\/content\/uploads\/2024\/04\/auth-next.jpg","width":1260,"height":630,"caption":"Guide to implement authentication with Next.js"},{"@type":"WebPage","@id":"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/#webpage","url":"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/","name":"Implementing Authentication in Next.js: A Step-by-Step Guide [REPO] | J - Desarrollo Aplicaciones Web","isPartOf":{"@id":"https:\/\/juannunezblasco.es\/#website"},"primaryImageOfPage":{"@id":"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/#primaryimage"},"datePublished":"2024-04-29T09:15:36+00:00","dateModified":"2024-05-08T18:48:33+00:00","breadcrumb":{"@id":"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/juannunezblasco.es\/en\/"},{"@type":"ListItem","position":2,"name":"Implementing Authentication in Next.js: A Step-by-Step Guide [REPO]"}]},{"@type":"Article","@id":"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/#article","isPartOf":{"@id":"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/#webpage"},"author":{"@id":"https:\/\/juannunezblasco.es\/#\/schema\/person\/31582cd4a29af7055b4c3b0508601b29"},"headline":"Implementing Authentication in Next.js: A Step-by-Step Guide [REPO]","datePublished":"2024-04-29T09:15:36+00:00","dateModified":"2024-05-08T18:48:33+00:00","mainEntityOfPage":{"@id":"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/#webpage"},"wordCount":838,"commentCount":0,"publisher":{"@id":"https:\/\/juannunezblasco.es\/#organization"},"image":{"@id":"https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/#primaryimage"},"thumbnailUrl":"https:\/\/juannunezblasco.es\/content\/uploads\/2024\/04\/auth-next.jpg","articleSection":["Next.js","React"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/juannunezblasco.es\/en\/autenticacion-nextjs\/#respond"]}]},{"@type":"Person","@id":"https:\/\/juannunezblasco.es\/#\/schema\/person\/31582cd4a29af7055b4c3b0508601b29","name":"Juan N\u00fa\u00f1ez Blaco","image":{"@type":"ImageObject","@id":"https:\/\/juannunezblasco.es\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/23b8417ac4b489153038755511de438e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/23b8417ac4b489153038755511de438e?s=96&d=mm&r=g","caption":"Juan N\u00fa\u00f1ez Blaco"},"description":"Full Stack Developer","sameAs":["https:\/\/juannunezblasco.es"],"url":"https:\/\/juannunezblasco.es\/en\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/juannunezblasco.es\/en\/wp-json\/wp\/v2\/posts\/4197"}],"collection":[{"href":"https:\/\/juannunezblasco.es\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/juannunezblasco.es\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/juannunezblasco.es\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/juannunezblasco.es\/en\/wp-json\/wp\/v2\/comments?post=4197"}],"version-history":[{"count":2,"href":"https:\/\/juannunezblasco.es\/en\/wp-json\/wp\/v2\/posts\/4197\/revisions"}],"predecessor-version":[{"id":4209,"href":"https:\/\/juannunezblasco.es\/en\/wp-json\/wp\/v2\/posts\/4197\/revisions\/4209"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/juannunezblasco.es\/en\/wp-json\/wp\/v2\/media\/4141"}],"wp:attachment":[{"href":"https:\/\/juannunezblasco.es\/en\/wp-json\/wp\/v2\/media?parent=4197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/juannunezblasco.es\/en\/wp-json\/wp\/v2\/categories?post=4197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/juannunezblasco.es\/en\/wp-json\/wp\/v2\/tags?post=4197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}