fix: token reload
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user