0

I am trying google signIn using angular2 and nodejs where angular2 and nodejs are running on 4200 and 3000 port respectively.So, when I click on SignIn with Google(button) it throws me an error as:

XMLHttpRequest cannot load https://accounts.google.com/o/oauth2/v2/auth?response_type=code&redirect_ur…d=287790791492-gjuv677chmkmqih4v1p6fc3jti32v76q.apps.googleusercontent.com. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

Although, I set headers on Node side...

I followed example on this link - https://github.com/kumartarun/JWT-with-Node-JS

How to solve this issue?

Samurai Jack
  • 2,985
  • 8
  • 35
  • 58
Smurfy
  • 31
  • 4
  • its a CORS issue, you need to add the headers in your node js app for allowing cross origin support – Rahul Singh Jun 27 '17 at 09:48
  • Possible duplicate of ["No 'Access-Control-Allow-Origin' header is present on the requested resource"](https://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource) – ponury-kostek Jun 27 '17 at 09:51
  • There is express middleware for cors. Have you tried it? – Lazyexpert Jun 27 '17 at 10:04
  • It's the _Google_ servers that are not accepting cross-domain requests, not your own server. There's not a lot you can do about that (although I don't see how the example code, which is server-side, comes into play). – robertklep Jun 27 '17 at 11:55
  • @Lazyexpert I used that express middleware still not working. – Smurfy Jun 28 '17 at 06:52
  • @robertklep I reffered same example from link https://github.com/kumartarun/JWT-with-Node-JS – Smurfy Jun 28 '17 at 06:54

1 Answers1

0

You should add cors to your nodejs app, something like this:

const express = require('express')
const cors = require('cors')
const app = express()

app.use(cors())
Cesar Tomatis
  • 598
  • 1
  • 4
  • 15