#Need super help with integrating Auth with React Frontend and nestjs backend (google auth in nestjs)

17 messages · Page 1 of 1 (latest)

tawny snow
#

I got google-strategy and I am using it to get the email and password and save it in db,

I am using passport

http://localhost:3000/api/v1/auth/google/login

I am able to login to google using nestjs running on 3000 and use proteched route

but not able to do any of the protected request, on react which is running on 3001

I tried, redirecting to server using an a <a> tag link, which point to the back-end server

can someone help me with this?

tawny snow
#

when I try to post a request after google login I get this,

fading bramble
# tawny snow when I try to post a request after google login I get this,

Enable CORS in your main.ts as it seems for loca dev
https://docs.nestjs.com/security/cors

unkempt flower
#

You can use proxy on your React App to go through this issue

tawny snow
tawny snow
unkempt flower
#

Your project use vite or create-react-app!?

tawny snow
#

it is made using nextjs

unkempt flower
#

Which version of nextjs?

tawny snow
#

latest

unkempt flower
tawny snow
#

sure

tawny snow
unkempt flower
#

next.config.js

module.exports = {
  async rewrites() {
    return [
      {
        source: '/api',
        destination: 'http://my-nest-api/post',
      },
    ]
  },
}

All call to http://localhost:your-react-app-port/api/posts will be redirect to http://my-nest-api/post

tawny snow
#

thanks