mirror of
https://github.com/wisplite/raster.git
synced 2026-05-01 06:32:44 -05:00
add access token validation logic and some media stuff
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user