Raw hardcode cookie and session on my CRUD project not working properly

The first request from a user will always have an empty session. You need to correctly handle this case before worrying about saving sessions.

I don’t know @nathanerr i even commented out the first if in index so i could just deal with templ alone. Just can explain how on earth it still render templates/admin/index.html.
I don’t know.

@CurtGreen thanks.

Randomly commenting out parts of your code won’t help you understand it.

If you follow the process I described, you will know what your code does and why it does it.

Put log.SetFlags(log.Lshortfile) at the beginning of main and then use log.Println or log.Printf to examine the value of every variable and see which branches of the if statements are followed.

okay did that @nathankerr , printed out an empty map. That’s no session created so none stored. I don’t know why. But maybe This is not the best way to do it.

The first time someone goes to the site, the session should be empty. How could they have a session if they were never there before?

@nathankerr i understand what you’re saying but don’t just know how to implement it.

What exactly don’t you know how to implement?

this whole authentication process with go.

What is the very first step of that process?

first get the inputs
then do checks
if checks all = true
create a session/cookie either in client/server side
save for that particular entity for a particular period of time
then other things…

What are the inputs?

form input, either username/email and password inputted by the particular user.

How does a user get to the point where they can enter their info?

open the page or site or url

At that point, what does the user’s session look like?

zero-value i think

How can you tell if they are logged in?

if they pass the checks and are redirected to main view/page etc

They are still on their first request. They have an empty session. The server hasn’t responded to them yet.

Is the user logged in? How can you tell?

i don’t know. the server should have responded