Get the Avatar in GoLang+HTMX #4953
Answered
by
ganigeorgiev
OfflinePing
asked this question in
Q&A
-
Hey, cookie, err := c.Cookie("pb_auth")
if err != nil {
fmt.Println(err)
return c.Redirect(http.StatusFound, "/login")
}
user := backend.CheckToken(cookie.Value)
if !user.Verified() {
return c.Redirect(http.StatusFound, "/login")
}
avatar := user.FindFileFieldByFile("avatar")
fmt.Println(avatar)
html, err := registry.LoadFiles("web/pages/dashboard.html").Render(map[string]interface{}{
"Username": user.Username(),
"Balance": user.GetString("balance") + "€",
"Email": user.Email(),
"Avatar": "",
})
if err != nil {
return err
}
return c.HTML(http.StatusOK, html) |
Beta Was this translation helpful? Give feedback.
Answered by
ganigeorgiev
May 18, 2024
Replies: 1 comment
-
If you want a url to the avatar file you'll have to construct it on your own (see File URL). One possible example could be: filename := user.GetString("avatar")
avatar := app.Settings().Meta.AppUrl + "/api/files/" + user.Collection().Id + "/" + user.Id + "/" + filename |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
OfflinePing
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FindFileFieldByFile
returns thefile
schema field associated with the file, not the file itself.If you want a url to the avatar file you'll have to construct it on your own (see File URL). One possible example could be: