Adds JWT-based auth with refresh tokens
This commit is contained in:
@@ -6,4 +6,5 @@ typealias FoundId = UUID
|
||||
typealias HuntId = UUID
|
||||
typealias HunterId = UUID
|
||||
typealias ItemId = UUID
|
||||
typealias TeamId = UUID
|
||||
typealias TeamId = UUID
|
||||
typealias RefreshId = UUID
|
||||
@@ -3,7 +3,6 @@ package net.halfbinary.scavengerhuntapi.model.converter
|
||||
import net.halfbinary.scavengerhuntapi.model.domain.Hunter
|
||||
import net.halfbinary.scavengerhuntapi.model.record.HunterRecord
|
||||
import net.halfbinary.scavengerhuntapi.model.request.HunterSignupRequest
|
||||
import net.halfbinary.scavengerhuntapi.model.response.LoginResponse
|
||||
|
||||
fun HunterSignupRequest.toDomain(): Hunter {
|
||||
return Hunter(
|
||||
@@ -20,8 +19,4 @@ fun Hunter.toRecord(): HunterRecord {
|
||||
|
||||
fun HunterRecord.toDomain(): Hunter {
|
||||
return Hunter(id, email, name, password, isAdmin)
|
||||
}
|
||||
|
||||
fun Hunter.toLoginResponse(): LoginResponse {
|
||||
return LoginResponse(email, name)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package net.halfbinary.scavengerhuntapi.model.record
|
||||
|
||||
import jakarta.persistence.Entity
|
||||
import jakarta.persistence.Id
|
||||
import jakarta.persistence.Table
|
||||
import net.halfbinary.scavengerhuntapi.model.RefreshId
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@Entity
|
||||
@Table(name = "refresh_token")
|
||||
data class RefreshTokenRecord(
|
||||
@Id
|
||||
val token: RefreshId,
|
||||
val email: String,
|
||||
val expiryDateTime: LocalDateTime
|
||||
)
|
||||
@@ -0,0 +1,9 @@
|
||||
package net.halfbinary.scavengerhuntapi.model.request
|
||||
|
||||
import jakarta.validation.constraints.NotBlank
|
||||
import net.halfbinary.scavengerhuntapi.model.RefreshId
|
||||
|
||||
data class LogoutRequest(
|
||||
@field:NotBlank(message = "You must provide a refresh token.")
|
||||
val refreshToken: RefreshId
|
||||
)
|
||||
@@ -0,0 +1,9 @@
|
||||
package net.halfbinary.scavengerhuntapi.model.request
|
||||
|
||||
import jakarta.validation.constraints.NotBlank
|
||||
import net.halfbinary.scavengerhuntapi.model.RefreshId
|
||||
|
||||
data class RefreshRequest(
|
||||
@field:NotBlank(message = "Refresh token cannot be blank")
|
||||
val refreshToken: RefreshId,
|
||||
)
|
||||
@@ -1,6 +1,8 @@
|
||||
package net.halfbinary.scavengerhuntapi.model.response
|
||||
|
||||
import net.halfbinary.scavengerhuntapi.model.RefreshId
|
||||
|
||||
data class LoginResponse(
|
||||
val email: String,
|
||||
val name: String
|
||||
val accessToken: String,
|
||||
val refreshToken: RefreshId
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user