#Is login in admin the same as login in app?

3 messages · Page 1 of 1 (latest)

tidal heron
#

I tried to create login in my app like this:

export const Login = async ({ name, email, password }: Credentials) => {
  console.log('Creating user with:', name, email, password)
  try {
    const response = await fetch('http://localhost:3000/api/users/login', {
      method: 'POST',
      credentials: 'include',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        // name,
        email,
        password,
      }),
    })
    const data = await response.json()
    console.log('response ===>>>', data)

    if (response.ok) {
      console.log('Yes-----------------------------------')
    } else {
      console.log('NO user(((')
    }
  } catch (error) {
    console.log(error)
  }
}

and it kinda passes the auth.. but it does not send any cookie and basically does not login in a way logging with normal payload login form does..
Also, even more interesting question. How can I implement creating a user on my app, e.g. registering?

sour horizonBOT
hexed zealot
#

need more information, what is "your app" , Your code looks correct

this is a tutorial for a nextjs app logging into a payload cms backend https://youtu.be/9SZYwfkerZY

Payload CMS Authentication in Next.js: Login, Logout, Middleware, & API Security

Learn how to add robust authentication and route protection to your Next.js 14 applications using Payload CMS! This in-depth tutorial builds on our previous to-do app example (link: https://www.youtube.com/watch?v=v_ga0nzm-wU) and walks you through implementing a ...

▶ Play video