Hi All, I am trying out supertokens to replace our...
# support-questions-legacy
i
Hi All, I am trying out supertokens to replace our current auth but I am a bit stuck and would appreciate some help. I kept getting
Access to fetch at 'http://localhost:8086/auth/signin' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled
Front end: React/create-react-app Backend: Fastify. I've read some other thread that I need to register cors first before supertokens.init() but this wouldn't work because of
getInstanceOrThrowError().getAllCORSHeaders()
will throw error if I initialize it before. Tried hardcoding my cors plugin like this since for emailpassword only two extra headers anyway.
Copy code
module.exports = fp(async function (fastify, opts, next) {
  await fastify.register(cors, {
    origin: 'http://localhost:3000',
    allowedHeaders: ['content-type', 'rid', 'fdi-version'],
    methods: ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS', 'HEAD'],
    credentials: true,
  });
});
I feel like I have followed the documentation properly. What am I missing here exactly?
r
hey @iqrammm
you should call supertokens.init before the CORS registration, but you should also make sure that the CORS plugin is registered before the supertokens plugin.
i
thanks @rp_st ! now I understood what went wrong. I got confused with supertokens.init() with the plugin.
r
Fair.