L
L
lexstile2021-12-13 14:15:42
PHP
lexstile, 2021-12-13 14:15:42

How to set up FE (localhost) to BE (remote server) interaction with withCredentials?

It is necessary to send a request from the local machine to the remote server/hosting.
The method is called by the POST method to the url: https://site.ru/v1/auth/login

At the moment, the request is not made due to a CORS error.

Headers (php):

header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Methods: *');
header('Access-Control-Allow-Headers: *');


UPD: I figured out the headers - the method call worked. But how to put a cookie from a third-party server on localhost?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Dubrovin, 2021-12-13
@lexstile

Usually, authorization returns a token (for example, in the form of a JWT) that is passed to the frontend, the frontend verifies the token by verifying the signature or a server side request and sets the cookie.

S
Stalker_RED, 2015-07-01
@danil_prishepin

You can change it so that there is always at least one .current element
Or check for zero if($(".tabs-home__nav__item a.current").lenght == 0) and substitute some default value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question