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

Doesn’t the response depend on if the user is logged in or not? If so, the server can’t respond until it figures out if the user is logged in or not.

so how does it do that?

It looks at the session.

isn’t the session supposed to be created after the checks are okay? so the server can now respond based on the session?

As you stated before, the session is at its zero value.

Can you tell from that if the user is logged in or not?

not logged in

Correct.

How do you know that?

cos there’s no session

Would the existence of a session mean the user was logged in?

yeah(specific value)

The existence of a session does not mean a user is logged in.

The existence of a specific value in a session means the user is logged in.

How would you set a variable isLoggedIn based on this?

var isLoggedIn bool

if isLoggedIn == true { templates.ExecuteTemplate(w, "index.html", nil) }

set, not use.

`

cookie := &http.Cookie{
Name: “logged-in”,
Value: “1”,
}
IsLoggedIn = true
http.SetCookie(res, cookie)
http.Redirect(res, req, “/”, 302)
return

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.