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?
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