簡體   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用戶正常,但登錄會引發錯誤。

這是用於登錄和 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(); }

注銷時我刪除了 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(); }

這是 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 }) } }

我相信問題是由於您在本地主機上使用https協議造成的。 除非您在本地計算機上運行通過https提供內容的服務器,否則您應該使用http

所以代替這個: const URL = 'https://localhost:5000/auth';

試試這個: const URL = 'http://localhost:5000/auth';

我希望這有幫助:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM