简体   繁体   中英

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.

This is the Auth.jsx for login and singnup:

 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:

 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:

 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. Unless you have a server running on your local machine that serves the content via https , you should use http .

So instead of this: const URL = 'https://localhost:5000/auth';

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

I hope this helps:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM