mirror of
https://gitlab.com/foxixus/neomovies-api.git
synced 2025-10-28 01:48:51 +05:00
feat: implement JWT refresh token mechanism and improve auth
This commit is contained in:
@@ -21,4 +21,4 @@ type FavoriteRequest struct {
|
||||
MediaType string `json:"mediaType" validate:"required,oneof=movie tv"`
|
||||
Title string `json:"title" validate:"required"`
|
||||
PosterPath string `json:"posterPath"`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,21 +7,22 @@ import (
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
Email string `json:"email" bson:"email" validate:"required,email"`
|
||||
Password string `json:"-" bson:"password" validate:"required,min=6"`
|
||||
Name string `json:"name" bson:"name" validate:"required"`
|
||||
Avatar string `json:"avatar" bson:"avatar"`
|
||||
Favorites []string `json:"favorites" bson:"favorites"`
|
||||
Verified bool `json:"verified" bson:"verified"`
|
||||
VerificationCode string `json:"-" bson:"verificationCode,omitempty"`
|
||||
VerificationExpires time.Time `json:"-" bson:"verificationExpires,omitempty"`
|
||||
IsAdmin bool `json:"isAdmin" bson:"isAdmin"`
|
||||
AdminVerified bool `json:"adminVerified" bson:"adminVerified"`
|
||||
CreatedAt time.Time `json:"created_at" bson:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updated_at" bson:"updatedAt"`
|
||||
Provider string `json:"provider,omitempty" bson:"provider,omitempty"`
|
||||
GoogleID string `json:"googleId,omitempty" bson:"googleId,omitempty"`
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
Email string `json:"email" bson:"email" validate:"required,email"`
|
||||
Password string `json:"-" bson:"password" validate:"required,min=6"`
|
||||
Name string `json:"name" bson:"name" validate:"required"`
|
||||
Avatar string `json:"avatar" bson:"avatar"`
|
||||
Favorites []string `json:"favorites" bson:"favorites"`
|
||||
Verified bool `json:"verified" bson:"verified"`
|
||||
VerificationCode string `json:"-" bson:"verificationCode,omitempty"`
|
||||
VerificationExpires time.Time `json:"-" bson:"verificationExpires,omitempty"`
|
||||
IsAdmin bool `json:"isAdmin" bson:"isAdmin"`
|
||||
AdminVerified bool `json:"adminVerified" bson:"adminVerified"`
|
||||
CreatedAt time.Time `json:"created_at" bson:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updated_at" bson:"updatedAt"`
|
||||
Provider string `json:"provider,omitempty" bson:"provider,omitempty"`
|
||||
GoogleID string `json:"googleId,omitempty" bson:"googleId,omitempty"`
|
||||
RefreshTokens []RefreshToken `json:"-" bson:"refreshTokens,omitempty"`
|
||||
}
|
||||
|
||||
type LoginRequest struct {
|
||||
@@ -36,8 +37,9 @@ type RegisterRequest struct {
|
||||
}
|
||||
|
||||
type AuthResponse struct {
|
||||
Token string `json:"token"`
|
||||
User User `json:"user"`
|
||||
Token string `json:"token"`
|
||||
RefreshToken string `json:"refreshToken"`
|
||||
User User `json:"user"`
|
||||
}
|
||||
|
||||
type VerifyEmailRequest struct {
|
||||
@@ -47,4 +49,21 @@ type VerifyEmailRequest struct {
|
||||
|
||||
type ResendCodeRequest struct {
|
||||
Email string `json:"email" validate:"required,email"`
|
||||
}
|
||||
}
|
||||
|
||||
type RefreshToken struct {
|
||||
Token string `json:"token" bson:"token"`
|
||||
ExpiresAt time.Time `json:"expiresAt" bson:"expiresAt"`
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
|
||||
UserAgent string `json:"userAgent,omitempty" bson:"userAgent,omitempty"`
|
||||
IPAddress string `json:"ipAddress,omitempty" bson:"ipAddress,omitempty"`
|
||||
}
|
||||
|
||||
type TokenPair struct {
|
||||
AccessToken string `json:"accessToken"`
|
||||
RefreshToken string `json:"refreshToken"`
|
||||
}
|
||||
|
||||
type RefreshTokenRequest struct {
|
||||
RefreshToken string `json:"refreshToken" validate:"required"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user