@@ -43,7 +43,7 @@ func (app *application) createAuthenticationTokenHandler(c echo.Context) error {
4343 if ! admin .Activated {
4444 return c .JSON (http .StatusBadRequest , envelope {"error" : "admin not activated" })
4545 }
46-
46+
4747 pwd := db.Password {
4848 Hash : admin .PasswordHash ,
4949 Plaintext : input .Password ,
@@ -62,13 +62,14 @@ func (app *application) createAuthenticationTokenHandler(c echo.Context) error {
6262 return c .JSON (http .StatusUnauthorized , envelope {"error" : "invalid phone number or password" })
6363 }
6464
65- token , err := app .store .NewToken (admin .ID , 3 * 24 * time .Hour , db .ScopeAuthentication )
65+ expiry := time .Now ().Add (3 * 24 * time .Hour )
66+ token , err := app .store .NewToken (admin .ID , expiry , db .ScopeAuthentication )
6667 if err != nil {
6768 slog .Error ("error generating new token" , "error" , err )
6869 return c .JSON (http .StatusInternalServerError , envelope {"error" : "internal server error" })
6970 }
7071
71- return c .JSON (http .StatusCreated , envelope {"token" : token .Plaintext })
72+ return c .JSON (http .StatusCreated , envelope {"token" : token .Plaintext , "expiry" : expiry })
7273}
7374
7475func (app * application ) createPasswordResetTokenHandler (c echo.Context ) error {
@@ -102,7 +103,9 @@ func (app *application) createPasswordResetTokenHandler(c echo.Context) error {
102103 return c .JSON (http .StatusForbidden , envelope {"errors" : "account not activated" })
103104 }
104105
105- token , err := app .store .NewToken (admin .ID , 45 * time .Minute , db .ScopePasswordReset )
106+ expiry := time .Now ().Add (45 * time .Minute )
107+
108+ token , err := app .store .NewToken (admin .ID , expiry , db .ScopePasswordReset )
106109 if err != nil {
107110 slog .Error ("error generating new token" , "error" , err )
108111 return c .JSON (http .StatusInternalServerError , envelope {"error" : "internal server error" })
@@ -151,7 +154,9 @@ func (app *application) createActivationTokenHandler(c echo.Context) error {
151154 return c .JSON (http .StatusForbidden , envelope {"errors" : "account already activated" })
152155 }
153156
154- token , err := app .store .NewToken (admin .ID , 3 * 24 * time .Hour , db .ScopeActivation )
157+ expiry := time .Now ().Add (3 * 24 * time .Hour )
158+
159+ token , err := app .store .NewToken (admin .ID , expiry , db .ScopeActivation )
155160 if err != nil {
156161 slog .Error ("error generating new token" , "error" , err )
157162 return c .JSON (http .StatusInternalServerError , envelope {"error" : "internal server error" })
0 commit comments