implemented login logic
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
@@ -11,10 +12,10 @@ import (
|
||||
|
||||
var secretKey = []byte("replace-with-env-variable")
|
||||
|
||||
func GetToken(userID string) (string, error) {
|
||||
func GetToken(user *User) (string, error) {
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256,
|
||||
jwt.RegisteredClaims{
|
||||
Subject: userID,
|
||||
Subject: strconv.Itoa(int(user.Id)),
|
||||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Hour)),
|
||||
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user