Quiero hacer una interfaz con vue con odoo como backend. Pero cada vez que hago una solicitud a través de axios a odoo, aparece un error CORS.
Los siguientes son dos métodos de controlador en odoo.
@http.route('/login', type='json', auth='none', cors='http://127.0.0.1:5173', csrf=False, methods=['OPTIONS', 'POST']) def login(self, db, login, password): http.request.session.authenticate(db, login, password) return http.request.env['ir.http'].session_info() @http.route('/logout', type='json', auth='user', cors='http://127.0.0.1:5173', csrf=False, methods=['OPTIONS', 'POST']) def logout(self): return {'test'} http.request.session.logout()El código de la solicitud en JS es el siguiente
async function login() { axios.post('http://127.0.0.1:8069/login', { jsonrpc: "2.0", params: { db: "db_name", login: email.value, password: password.value }, }, { headers: {"content-type": "application/json"}, withCredentials: true, }) .then(content => { console.log(content.data) }) .catch(error => alert(error)) } async function logout() { axios.post('http://127.0.0.1:8069/logout', { "jsonrpc": "2.0", "params": {} }, { withCredentials: true, headers: {"Content-Type": "application/json"}, }) .then(content => { console.log(content.data) }) .catch(error => alert(error)) }Cuando saco los cors de los métodos del controlador, aparece el error
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.Cuando cors='*' y withCredentials=true entonces
The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.El inicio de sesión funciona cuando withCredentials es falso y cors='*' o cors la ip. Cuando es cierto me sale el siguiente error
The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'.Cerrar sesión nunca funciona. Cada vez que hay un error cors. Por ejemplo:
Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.¿Qué me estoy perdiendo? ¿Cómo llamo a la API de odoo de la manera correcta?