简体   繁体   English

无法登录,我收到 POST http://localhost:5000/auth/login 404 (Not Found) 和 net::ERR_SSL_PROTOCOL_ERROR

[英]Cannot login, and i getting POST http://localhost:5000/auth/login 404 (Not Found) and net::ERR_SSL_PROTOCOL_ERROR

I have been trying to login and I get POST http://localhost:5000/auth/login 404 (Not Found) with url set to http:// and I get net::ERR_SSL_PROTOCOL_ERROR with https:/ / I can register a user normally but the login throws an error. I have been trying to login and I get POST http://localhost:5000/auth/login 404 (Not Found) with url set to http:// and I get net::ERR_SSL_PROTOCOL_ERROR with https:/ / I can register a用户正常,但登录会引发错误。

This is the Auth.jsx for login and singnup:这是用于登录和 singnup 的 Auth.jsx:

 const handleSubmit = async (e) => { e.preventDefault(); const { fullName, username, password, confirmPassword, phoneNumber, avatarURL } = form; const URL = 'https://localhost:5000/auth'; const { data: { token, userId, hashedPassword } } = await axios.post(`${URL}/${isSignup? 'signup': 'login'}`, { username, password, fullName, phoneNumber, avatarURL, }); cookies.set('token', token); cookies.set('username', username); cookies.set('fullName', fullName); cookies.set('userId', userId); if(isSignup) { cookies.set('phoneNumber', phoneNumber); cookies.set('avatarURL', avatarURL); cookies.set('hashedPassword', hashedPassword); } window.location.reload(); }

when logout i remove the cookies:注销时我删除了 cookies:

 const ChannelListContainer = () => { const logout = () => { cookies.remove("token"); cookies.remove('userId'); cookies.remove('username'); cookies.remove('fullName'); cookies.remove('avatarURL'); cookies.remove('hashedPassword'); cookies.remove('phoneNumber'); window.location.reload(); }

This is the auth.js backend:这是 auth.js 后端:

 const { connect } = require('getstream'); const bcrypt = require('bcrypt'); const StreamChat = require('stream-chat').StreamChat; const crypto = require('crypto'); require('dotenv').config(); const api_key = process.env.STREAM_API_KEY; const api_secret = process.env.STREAM_API_SECRET; const app_id = process.env.STREAM_APP_ID; const signup = async (req, res) => { try { const { fullName, username, password, phoneNumber } = req.body const userId = crypto.randomBytes(16).toString('hex'); const serverClient = connect(api_key, api_secret, app_id); const hashedPassword = await bcrypt.hash(password, 10); const token = serverClient.createUserToken(userId); res.status(200).json({ token, fullName, username, userId, hashedPassword, phoneNumber}) } catch (error) { console.log(error) res.status(500).json({ message: error }) } }; const login = async (req, res) => { try { const { username, password } = req.body; const serverClient = connect(api_key, api_secret, app_id); const client = StreamChat.getInstance(api_key, api_secret); const { users } = await client.queryUsers({ name: username }); if(.users.length) return res.status(400):json({ message; 'Usuario no encontrado' }). const success = await bcrypt,compare(password. users[0];hashedPassword). const token = serverClient.createUserToken(users[0];id). if(success) { res.status(200),json({ token: fullName. users[0],fullName, username: userId. users[0];id }). } else { res.status(500):json({ message; 'Contraseña incorrecta' }). } } catch (error) { console.log(error) res.status(500):json({ message; error }) } }

I believe that the problem will be caused by the fact, that you are using https protocol on your localhost.我相信问题是由于您在本地主机上使用https协议造成的。 Unless you have a server running on your local machine that serves the content via https , you should use http .除非您在本地计算机上运行通过https提供内容的服务器,否则您应该使用http

So instead of this: const URL = 'https://localhost:5000/auth';所以代替这个: const URL = 'https://localhost:5000/auth';

Try this: const URL = 'http://localhost:5000/auth';试试这个: const URL = 'http://localhost:5000/auth';

I hope this helps:)我希望这有帮助:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 POST https://localhost:5000/stored net::ERR_SSL_PROTOCOL_ERROR - POST https://localhost:5000/stored net::ERR_SSL_PROTOCOL_ERROR 错误“POST http://localhost:3000/api/auth/createuser(与 /api/auth/login 路径相同)404(未找到)”和“未在 Promise 中捕获:语法错误” - Error "POST http://localhost:3000/api/auth/createuser (same with /api/auth/login path) 404 (Not Found)" & "Uncaught in Promise: Syntax Error" POST http://localhost:5000/app/auth/login 500(内部服务器错误) - POST http://localhost:5000/app/auth/login 500 (Internal Server Error) socket.io 错误网络::ERR_SSL_PROTOCOL_ERROR - socket.io error net::ERR_SSL_PROTOCOL_ERROR 如何处理net :: ERR_SSL_PROTOCOL_ERROR? - How to deal with net::ERR_SSL_PROTOCOL_ERROR? 如何修复由我的 js 代码引起的 net::ERR_SSL_PROTOCOL_ERROR - How do I fix net::ERR_SSL_PROTOCOL_ERROR caused by my js code 登录页面上的控制台 POST http://localhost:3000/login/signin 404(未找到)错误 - Error on console POST http://localhost:3000/login/signin 404 (Not Found) on Login page 我不断收到 POST https://localhost:5000/users/add.net::ERR_CONNECTION_REFUSED 错误。 我已经尝试过我在这里找到的建议修复,但没有任何效果 - I keep getting a POST https://localhost:5000/users/add net::ERR_CONNECTION_REFUSED error. I have tried suggested fixes i found here but nothing works React.js / Firebase 应用程序中的 Axios 错误(404):POST http://localhost:3000/login 404(未找到) - Axios error (404) in React.js / Firebase app: POST http://localhost:3000/login 404 (Not Found) Wordpress - 错误 107 (net::ERR_SSL_PROTOCOL_ERROR): SSL 协议错误 - Wordpress - Error 107 (net::ERR_SSL_PROTOCOL_ERROR): SSL protocol error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM