Skip to content

Commit

Permalink
fix: delete cookie for be
Browse files Browse the repository at this point in the history
dev: add avatar for user
  • Loading branch information
NLNM-0-0 committed Dec 24, 2023
1 parent 99ab6af commit 73343a3
Show file tree
Hide file tree
Showing 17 changed files with 253 additions and 197 deletions.
7 changes: 0 additions & 7 deletions book-store-management-backend/common/app_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,7 @@ func ErrRecordNotFound() *AppError {
)
}

var ErrTokenExpired = NewCustomError(
errTokenExpired,
fmt.Sprintf("Đã có lỗi xảy ra. Xin hãy đăng nhập lại."),
fmt.Sprintf("ErrTokenExpired"),
)

var (
errRecordNotFound = errors.New("record not found")
errIdIsTooLong = errors.New("id is too long")
errTokenExpired = errors.New("token is expired")
)
8 changes: 0 additions & 8 deletions book-store-management-backend/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,4 @@ const RoleAdminId = "admin"

const DefaultPass = "app123"

const AccessTokenStrInCookie = "accessToken"
const RefreshTokenStrInCookie = "refreshToken"

const CurrentUserStr = "current_user"
const AccessTokenStr = "access_token"
const RefreshTokenStr = "refresh_token"

const MaxAgeAccessToken = 60 * 60 * 24
const MaxAgeRefreshToken = 60 * 60 * 24 * 3
111 changes: 79 additions & 32 deletions book-store-management-backend/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1219,9 +1219,9 @@ const docTemplate = `{
],
"responses": {
"200": {
"description": "status of response",
"description": "user token",
"schema": {
"$ref": "#/definitions/common.ResSuccess"
"$ref": "#/definitions/usermodel.Account"
}
},
"400": {
Expand Down Expand Up @@ -1346,11 +1346,22 @@ const docTemplate = `{
"auth"
],
"summary": "Refresh token",
"parameters": [
{
"description": "refreshToken",
"name": "refreshToken",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/usermodel.ReqRefreshToken"
}
}
],
"responses": {
"200": {
"description": "status of response",
"description": "user token",
"schema": {
"$ref": "#/definitions/common.ResSuccess"
"$ref": "#/definitions/usermodel.AccountWithoutRefresh"
}
},
"400": {
Expand Down Expand Up @@ -1660,34 +1671,6 @@ const docTemplate = `{
}
}
},
"/signOut": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "SignOut",
"responses": {
"200": {
"description": "status of response",
"schema": {
"$ref": "#/definitions/common.ResSuccess"
}
},
"400": {
"description": "error",
"schema": {
"$ref": "#/definitions/common.AppError"
}
}
}
}
},
"/suppliers": {
"get": {
"security": [
Expand Down Expand Up @@ -2790,6 +2773,10 @@ const docTemplate = `{
"type": "string",
"example": "bookId"
},
"img": {
"type": "string",
"example": "https://picsum.photos/200"
},
"importPrice": {
"type": "integer",
"example": 100000
Expand Down Expand Up @@ -4505,6 +4492,42 @@ const docTemplate = `{
}
}
},
"tokenprovider.Token": {
"type": "object",
"properties": {
"created": {
"type": "string",
"example": "2023-12-03T15:02:19.62113565Z"
},
"expiry": {
"type": "integer",
"example": 2592000
},
"token": {
"type": "string",
"example": "token"
}
}
},
"usermodel.Account": {
"type": "object",
"properties": {
"accessToken": {
"$ref": "#/definitions/tokenprovider.Token"
},
"refreshToken": {
"$ref": "#/definitions/tokenprovider.Token"
}
}
},
"usermodel.AccountWithoutRefresh": {
"type": "object",
"properties": {
"accessToken": {
"$ref": "#/definitions/tokenprovider.Token"
}
}
},
"usermodel.Filter": {
"type": "object",
"properties": {
Expand All @@ -4529,6 +4552,10 @@ const docTemplate = `{
"type": "string",
"example": "[email protected]"
},
"img": {
"type": "string",
"example": "https://picsum.photos/200"
},
"name": {
"type": "string",
"example": "Nguyễn Văn A"
Expand Down Expand Up @@ -4556,6 +4583,14 @@ const docTemplate = `{
}
}
},
"usermodel.ReqRefreshToken": {
"type": "object",
"properties": {
"refreshToken": {
"type": "string"
}
}
},
"usermodel.ReqResetPasswordUser": {
"type": "object",
"properties": {
Expand All @@ -4572,6 +4607,10 @@ const docTemplate = `{
"type": "string",
"example": "bỏ trường này nếu không muốn update địa chỉ"
},
"img": {
"type": "string",
"example": "https://picsum.photos/200"
},
"name": {
"type": "string",
"example": "bỏ trường này nếu không muốn update tên"
Expand Down Expand Up @@ -4683,6 +4722,10 @@ const docTemplate = `{
"type": "string",
"example": "user id"
},
"img": {
"type": "string",
"example": "https://picsum.photos/200"
},
"isActive": {
"type": "boolean",
"example": true
Expand Down Expand Up @@ -4728,6 +4771,10 @@ const docTemplate = `{
"type": "string",
"example": "user id"
},
"img": {
"type": "string",
"example": "https://picsum.photos/200"
},
"isActive": {
"type": "boolean",
"example": true
Expand Down
111 changes: 79 additions & 32 deletions book-store-management-backend/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1213,9 +1213,9 @@
],
"responses": {
"200": {
"description": "status of response",
"description": "user token",
"schema": {
"$ref": "#/definitions/common.ResSuccess"
"$ref": "#/definitions/usermodel.Account"
}
},
"400": {
Expand Down Expand Up @@ -1340,11 +1340,22 @@
"auth"
],
"summary": "Refresh token",
"parameters": [
{
"description": "refreshToken",
"name": "refreshToken",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/usermodel.ReqRefreshToken"
}
}
],
"responses": {
"200": {
"description": "status of response",
"description": "user token",
"schema": {
"$ref": "#/definitions/common.ResSuccess"
"$ref": "#/definitions/usermodel.AccountWithoutRefresh"
}
},
"400": {
Expand Down Expand Up @@ -1654,34 +1665,6 @@
}
}
},
"/signOut": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "SignOut",
"responses": {
"200": {
"description": "status of response",
"schema": {
"$ref": "#/definitions/common.ResSuccess"
}
},
"400": {
"description": "error",
"schema": {
"$ref": "#/definitions/common.AppError"
}
}
}
}
},
"/suppliers": {
"get": {
"security": [
Expand Down Expand Up @@ -2784,6 +2767,10 @@
"type": "string",
"example": "bookId"
},
"img": {
"type": "string",
"example": "https://picsum.photos/200"
},
"importPrice": {
"type": "integer",
"example": 100000
Expand Down Expand Up @@ -4499,6 +4486,42 @@
}
}
},
"tokenprovider.Token": {
"type": "object",
"properties": {
"created": {
"type": "string",
"example": "2023-12-03T15:02:19.62113565Z"
},
"expiry": {
"type": "integer",
"example": 2592000
},
"token": {
"type": "string",
"example": "token"
}
}
},
"usermodel.Account": {
"type": "object",
"properties": {
"accessToken": {
"$ref": "#/definitions/tokenprovider.Token"
},
"refreshToken": {
"$ref": "#/definitions/tokenprovider.Token"
}
}
},
"usermodel.AccountWithoutRefresh": {
"type": "object",
"properties": {
"accessToken": {
"$ref": "#/definitions/tokenprovider.Token"
}
}
},
"usermodel.Filter": {
"type": "object",
"properties": {
Expand All @@ -4523,6 +4546,10 @@
"type": "string",
"example": "[email protected]"
},
"img": {
"type": "string",
"example": "https://picsum.photos/200"
},
"name": {
"type": "string",
"example": "Nguyễn Văn A"
Expand Down Expand Up @@ -4550,6 +4577,14 @@
}
}
},
"usermodel.ReqRefreshToken": {
"type": "object",
"properties": {
"refreshToken": {
"type": "string"
}
}
},
"usermodel.ReqResetPasswordUser": {
"type": "object",
"properties": {
Expand All @@ -4566,6 +4601,10 @@
"type": "string",
"example": "bỏ trường này nếu không muốn update địa chỉ"
},
"img": {
"type": "string",
"example": "https://picsum.photos/200"
},
"name": {
"type": "string",
"example": "bỏ trường này nếu không muốn update tên"
Expand Down Expand Up @@ -4677,6 +4716,10 @@
"type": "string",
"example": "user id"
},
"img": {
"type": "string",
"example": "https://picsum.photos/200"
},
"isActive": {
"type": "boolean",
"example": true
Expand Down Expand Up @@ -4722,6 +4765,10 @@
"type": "string",
"example": "user id"
},
"img": {
"type": "string",
"example": "https://picsum.photos/200"
},
"isActive": {
"type": "boolean",
"example": true
Expand Down
Loading

0 comments on commit 73343a3

Please sign in to comment.