add access token validation logic and some media stuff

This commit is contained in:
wisplite
2025-11-22 19:51:26 -06:00
parent a78003b5a3
commit fe849f558c
6 changed files with 116 additions and 1 deletions
+13
View File
@@ -1,6 +1,7 @@
package services
import (
"fmt"
"time"
"github.com/google/uuid"
@@ -22,3 +23,15 @@ func CreateAccessToken(userID string) (models.AccessToken, error) {
}
return accessToken, nil
}
func ValidateAccessToken(accessToken string) (string, error) {
accessTokenModel := models.AccessToken{}
result := db.GetDB().First(&accessTokenModel, "token = ?", accessToken)
if result.Error != nil {
return "", result.Error
}
if accessTokenModel.Expires.Before(time.Now()) {
return "", fmt.Errorf("access token expired")
}
return accessTokenModel.UserID, nil
}