Adds JWT-based auth with refresh tokens

This commit is contained in:
2026-04-09 15:57:26 -05:00
parent 3a53769421
commit 9633d95e75
21 changed files with 426 additions and 48 deletions

View File

@@ -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

View File

@@ -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)
}

View File

@@ -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
)

View File

@@ -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
)

View File

@@ -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,
)

View File

@@ -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
)