fix: token reload

This commit is contained in:
Rogee
2024-12-15 01:19:03 +08:00
parent ed3d8b0e6c
commit 4a606bd824
9 changed files with 62 additions and 23 deletions

View File

@@ -26,6 +26,18 @@ type Controller struct {
}
func (c *Controller) Render(ctx fiber.Ctx) error {
jwtToken := ctx.Cookies("token")
ctx.Set("Content-Type", "text/html")
b, err := os.ReadFile(filepath.Join(c.storagePath.Asset, "index.html"))
if err != nil {
return errors.Wrap(err, "failed to read file")
}
if jwtToken != "" {
html := strings.ReplaceAll(string(b), "{{JWT}}", jwtToken)
return ctx.SendString(html)
}
code := ctx.Query("code")
// get the openid
@@ -58,18 +70,17 @@ func (c *Controller) Render(ctx fiber.Ctx) error {
UserID: user.ID,
TenantID: tenant.ID,
})
jwtToken, err := c.jwt.CreateToken(claim)
jwtToken, err = c.jwt.CreateToken(claim)
if err != nil {
return errors.Wrap(err, "failed to create token")
}
b, err := os.ReadFile(filepath.Join(c.storagePath.Asset, "index.html"))
if err != nil {
return errors.Wrap(err, "failed to read file")
}
ctx.Cookie(&fiber.Cookie{
Name: "token",
Value: jwtToken,
HTTPOnly: true,
})
html := strings.ReplaceAll(string(b), "{{JWT}}", jwtToken)
ctx.Set("Content-Type", "text/html")
return ctx.SendString(html)
}