#ot | Emma still sucks at coding and then need help again
1 messages · Page 1 of 1 (latest)
howdy
what does that mean 😭
yes that
@stone whaledo you know react and next js?
a bit yeah, what do you need help with?
when I click to register I have that ):
you're registering a route?
I don't have any fucking idea
well what does the code do at this line
that error is very generic so i can't help without more details
you can copy that and paste it here
ik
don't do https on localhost
bro
unless you have SSL setup, ofc
yeah
then make it
http://localhost:3001/register
but I'm in a team
and the other person has no clue either?
and if I don't do it they will have 0 too
they told me to search on internet
it's good you're working in a team at least, you'll very rarely work alone when you've graduated
... so they don't have any clue either
I think that the one who answered me does, but don't want to help me
lmao, I stop this school after this project
already?
I don't like it so yes
ok 🙂
I don't like to do programation every day
already know what you will do next?
programation
I want to work in motorsport
oooo
coding?
programming
programation sounds cool tho
that's odd, it looks like you have the syntax right
don't know precisely but in motorsport
no
@glossy phoenix did you try doing this
I copied and past a video
while the baseURL is 'https://localhost:3001/'
and on the video it works
yeah, but you can edit it
can you try that?
try what?
can you paste it as a codeblock here
I didn't understand what you said 
import { useState } from "react"
import NavBar from "../comps/NavBar";
import axios from 'axios';
export default function Register() {
const [registerUsername, setRegisterUsername ] = useState('');
const [registerPassword, setRegisterPassword ] = useState('');
const register = () => {
axios({
method: "post",
data: {
username: registerUsername,
password: registerPassword
},
withCredentials: true,
url: "http://localhost:3001/register"
}).then((res) => console.log(res)).catch((err) => console.log(err));
}
return (
<div>
<NavBar></NavBar>
<div>
{console.log(registerUsername)}
<h1>Inscription</h1>
<input type="text" name="username" placeholder="Pseudo" onChange={e => setRegisterUsername(e.target.value)}></input>
<input type="password" name="password" placeholder="Mot de passe" onChange={e => setRegisterUsername(e.target.value)}></input>
<button onClick={register}>Terminer</button>
</div>
</div>
)
}
noice
you have url: "https://localhost:3001/register"
this is register
it seems you need url: "/register" instead
and baseURL: "https://localhost:3001"
(in the docs of this axiom thingy they always use https 🤷♂️ )
yay
thx guys
you're welcome !
you are the best <3
you are amazing too 
i like helping you, cause often i have no clue about the stuff lol
lmao
can't be worst than me
also i lied, i've never done react nor nextjs
I'm ngl, not much of a programmer
but it doesn't matter
https://www.youtube.com/watch?v=WYHQP9lQgD8&t=1338s I can continue the video thx to you guys
Creating a website with Next Js along with an Express and MySQL server to register, login and atheneite users.
Downloads:
MySQL Workbench: https://dev.mysql.com/downloads/workbench/
Code:
https://github.com/SpaceWaffles5827/Login-And-Register-MySql-And-PassportJs
⏱️ Timestamps:
0:00 - Introduction
0:22 - Setup
2:28 - Basic Register Page
4:45 ...
I only know basic docker compose + extremely basic networking
xD
hf
i wish i had good frontend to do at work
and I don't have any clue about how to do it with react and next
you can do mine if you want lmao
i have to do a frontend for a webapp, without using html. quite cumbersome

lol
(this is why FOSS UI sucks /jk)
my frontend is just a login page and a registration page yk xD
basically every component is hand drawn at some point
if i want to add a button, it basically takes a white canvas
then goes: ok so we will choose this colour then draw a rectangle of this size at this position, then we change to this colour to draw a text of this dimensions at this position then on that rectangle we drew we will add a listener so that when we click on it it does this, if we hover it does this etc.
it's very heavy to write
rather than <input type="button" class="theClassThatWillHandleTheColourAndDimension" listener1="function1" listener2="function2">
where do you push data to your database
you're not querying the proper table lol
oh no you just called your database legin_register, my bad.
didn't want to do it
but
I did
so
you've seen the Utilisateur créé avec succès message?
instead of creating a new one
no
so what does it do when you call this new /register route of yours with the proper parameters
what's the result
wdym
you have called this route to expect an entry in your database right
maybe
I guess
@stone whalewhat am I supposed to do then? 
well you need to make sure your register route is called, is your form calling it
send the code for your form that should call the route 🙂
import { useState } from "react"
import NavBar from "../comps/NavBar";
import axios from 'axios';
export default function Register() {
const [registerUsername, setRegisterUsername ] = useState('');
const [registerPassword, setRegisterPassword ] = useState('');
const register = () => {
axios({
method: "post",
data: {
username: registerUsername,
password: registerPassword
},
withCredentials: true,
url: "/register"
}).then((res) => console.log(res)).catch((err) => console.log(err));
}
return (
<div>
<NavBar></NavBar>
<div>
{console.log(registerUsername)}
<h1>Inscription</h1>
<input type="text" name="username" placeholder="Pseudo" onChange={e => setRegisterUsername(e.target.value)}></input>
<input type="password" name="password" placeholder="Mot de passe" onChange={e => setRegisterPassword(e.target.value)}></input>
<button onClick={register}>Terminer</button>
</div>
</div>
)
}
right, what happens in your network tab of the browser dev tools when you click on the button
when you choose one of them register calls, like the last one on your pic, what's in there? parameters, result etc
also, anything in the console tab?
what's the playload?
there's a tab called payload in the request
on your last screen
the pay (not play) load is what you send alongside the request, basicallyu the parameters
@stone whale sry but I need to finish that today :c
this is the last time I will ask for your help 😭
then give me what i ask for 🙂
here!
.
and the response?
same, in the request, next to payload
sry
sry my parents were back home
put some console.log on your server function that should do the work of executing the sql queries, so we are sure we pass in every block
ok
I tried to put all in a const but doesn't work /:
wdym
no just put console.log to check we're executing the stuff inside
still doesn't work
const express = require('express');
const boddParser = require('body-parser');
const cors = require('cors');
const passport = require('passport');
const expressSession = require('express-session');
const cookieParser = require('cookie-parser');
const bcrypt = require('bcrypt');
const db = require('./db');
const app = express();
app.use(boddParser.json());
app.use(boddParser.urlencoded({ extended: true }));
app.use(expressSession({ secret: 'mySecretKey', resave:false, saveUninitialized: false }));
app.use(cors({
origin: 'http://localhost:3000',
credentials: true
}));
app.use(cookieParser('mySecretKey'));
app.use(passport.initialize());
app.use(passport.session());
app.get('/', (req, res) => {
res.send('Hello World')
})
app.post('/register', (req, res) => {
const username = req.body.username;
const password = req.body.password;
const query = "INSERT INRO account (`username`, `password`) VALUES (?, ?)";
const query2 = "SELECT * FROM account WHERE username = ?";
db.query(query2, [username], (err, result) =>{
if(err) {throw err;}
if(result.length > 0) {
res.send({message: "Ce nom d'utilisateur existe déjà"})
}
if(result.length === 0) {
const hashedPassword = bcrypt.hashSync(password, 10);
db.query(query, [username, password], (err, result) => {
if(err) {throw err;}
res.send({message: "Utilisateur créé avec succès"})
})
}
})
});
app.listen(3001, () => {
console.log('Server started on port 3001');
})
app.post('/register', (req, res) => {
const username = req.body.username;
const password = req.body.password;
const query = "INSERT INRO account (`username`, `password`) VALUES (?, ?)";
const query2 = "SELECT * FROM account WHERE username = ?";
console.log('in the register route');
db.query(query2, [username], (err, result) =>{
console.log('in the select query');
if(err) {throw err;}
if(result.length > 0) {
console.log('already found that user name');
res.send({message: "Ce nom d'utilisateur existe déjà"})
}
if(result.length === 0) {
console.log('about to use the insert query');
const hashedPassword = bcrypt.hashSync(password, 10);
db.query(query, [username, password], (err, result) => {
if(err) {throw err;}
console.log('insert query executed just fine');
res.send({message: "Utilisateur créé avec succès"})
})
}
})
});
nothing were logged
hmm that's what i expected
show the headers tab from the network tab on your request ? maybe you're not calling the proper url
you're calling on port 3000
while the server is on port 3001
that's because you haven't set the baseURL like i said, i suppose 😄
.
I have a server on 3001 and my page on 3000
yes and your page on 3000 is calling the server on 3000 as well, when it should be 3001
oh ok
so
here
app.use(cors({
origin: 'http://localhost:3000',
credentials: true
}));
it should be 3001, right?
hmmm no
where then? I don't understand... 
in your front application where you define the register function 🙂
there is no 3000 in my register
correct, so that means it keeps the baseURL you had when you called, which is the url you have in your address bar before the first /
so what should I do?
.
add that on your front application on the register function, next to the "url:" parameter
like that?
what does your register funciton looks like now
no, the code
import { useState } from "react"
import NavBar from "../comps/NavBar";
import axios from 'axios';
export default function Register() {
const [registerUsername, setRegisterUsername ] = useState('');
const [registerPassword, setRegisterPassword ] = useState('');
const register = () => {
axios({
method: "post",
data: {
username: registerUsername,
password: registerPassword
},
withCredentials: true,
url: "https://localhost:3001/"
}).then((res) => console.log(res)).catch((err) => console.log(err));
}
return (
<div>
<NavBar></NavBar>
<div>
{console.log(registerUsername)}
<h1>Inscription</h1>
<input type="text" name="username" placeholder="Pseudo" onChange={e => setRegisterUsername(e.target.value)}></input>
<input type="password" name="password" placeholder="Mot de passe" onChange={e => setRegisterPassword(e.target.value)}></input>
<button onClick={register}>Terminer</button>
</div>
</div>
)
}
right, as i expected
i think you're too stressed to pay attention to what i'm saying 😄
add
!= replace
still the same
nope
oh mb
there is smtg
an error
C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\protocol\Parser.js:437
throw err; // Rethrow non-MySQL errors
^
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
at Sequence._packetToError (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
at Handshake.ErrorPacket (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18)
at Protocol._parsePacket (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\protocol\Parser.js:433:10)
at Parser.write (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\protocol\Protocol.js:38:16)
at Socket.<anonymous> (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\Connection.js:88:28)
at Socket.<anonymous> (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\Connection.js:526:10)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
--------------------
at Protocol._enqueue (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at PoolConnection.connect (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\Connection.js:116:18)
at Pool.getConnection (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\Pool.js:48:16)
at Pool.query (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\Pool.js:202:8)
at C:\Autre\JavaScript\Yowl\yowl\server\index.js:42:8
at Layer.handle [as handle_request] (C:\Autre\JavaScript\Yowl\yowl\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Autre\JavaScript\Yowl\yowl\node_modules\express\lib\router\route.js:144:13)
at Route.dispatch (C:\Autre\JavaScript\Yowl\yowl\node_modules\express\lib\router\route.js:114:3)
at Layer.handle [as handle_request] (C:\Autre\JavaScript\Yowl\yowl\node_modules\express\lib\router\layer.js:95:5) {
code: 'ER_NOT_SUPPORTED_AUTH_MODE',
errno: 1251,
sqlMessage: 'Client does not support authentication protocol requested by server; consider upgrading MySQL client',
sqlState: '08004',
fatal: true
}
Node.js v18.12.1
[
ah so we're reaching the sql connection!
if you say so 😭
what is this db object in the server bit
const mysql = require('mysql');
const db = mysql.createPool({
connectionLimit: 10,
host: "localhost",
user: "root",
password: "password",
database: "legin_register"
});
module.exports = db;
and in your sql browser that you use to see the table empty, you connect as root with the password "password" ?
- Yes
- No I just didn't let my real password since I use it for a lot of things
ok, well for a small project like that you could actually make the password "password" tbf, it's not a real database 🙂
apparenly you could try this in the sql browser
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; -- where obviously 'password' is your password, if you want to keep it
FLUSH PRIVILEGES;
what software do you use, dbeaver?
I don't know how to use this shit
try to put it there
where's there?
where it's written SELECT * FROM...
I can't write there
hmm you can probably try something in the Query menu at the box, something like new script sql
try another of the menu items, it should open just a text input to put your sql
I definitely don't find anything
oh at the top left, the icon with a sheet that says sql+ ?
oh yes, mb
ok try to execute the query again
you might have to restart the node server just in case
no erm, the register thingy
do we have a different error in the node console
Server started on port 3001
in the register route
in the select query
C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\protocol\Parser.js:437
throw err; // Rethrow non-MySQL errors
^
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: YES)
at Sequence._packetToError (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
at Handshake.ErrorPacket (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18)
at Protocol._parsePacket (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\protocol\Parser.js:433:10)
at Parser.write (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\protocol\Protocol.js:38:16)
at Socket.<anonymous> (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\Connection.js:88:28)
at Socket.<anonymous> (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\Connection.js:526:10)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
--------------------
at Protocol._enqueue (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at PoolConnection.connect (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\Connection.js:116:18)
at Pool.getConnection (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\Pool.js:48:16)
at Pool.query (C:\Autre\JavaScript\Yowl\yowl\node_modules\mysql\lib\Pool.js:202:8)
at C:\Autre\JavaScript\Yowl\yowl\server\index.js:42:8
at Layer.handle [as handle_request] (C:\Autre\JavaScript\Yowl\yowl\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Autre\JavaScript\Yowl\yowl\node_modules\express\lib\router\route.js:144:13)
at Route.dispatch (C:\Autre\JavaScript\Yowl\yowl\node_modules\express\lib\router\route.js:114:3)
at Layer.handle [as handle_request] (C:\Autre\JavaScript\Yowl\yowl\node_modules\express\lib\router\layer.js:95:5) {
code: 'ER_ACCESS_DENIED_ERROR',
errno: 1045,
sqlMessage: "Access denied for user 'root'@'localhost' (using password: YES)",
sqlState: '28000',
fatal: true
}
Node.js v18.12.1
[nodemon] app crashed - waiting for file changes before starting...
you've used the same password as before or you swapped to 'password' as i wrote it
I swapped it only on discord
ok 🙂 well that's odd it says you can't connect now 🤔
🥲
ok we'll revert it
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
then close your node server and do this npm un mysql && npm i mysql2
you might need to change the import in your db file on the server file to do
const mysql = require('mysql2');
done
@stone whaleisn't the origine of the problem that it tries to use password YES?
no, it says it's using a password to connect 🙂 there are methods that don't
ok sorry
I'm looking on internet but don't understand anything...
again, you didn't forget to replace your password in the sql commands just above?
I never edited it in VSCode
you just need to have them match, in the node server file, and on the mysql server
