Persists login cookie between browser restarts
This commit is contained in:
parent
934820274b
commit
1b79635ffa
@ -71,7 +71,7 @@ val serverModule = module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val userModule = module {
|
val userModule = module {
|
||||||
single { UserController(get(), get()) }
|
single { UserController(get(), get(), get()) }
|
||||||
single { UserView(get()) }
|
single { UserView(get()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import be.simplenotes.domain.usecases.login.*
|
|||||||
import be.simplenotes.domain.usecases.register.InvalidRegisterForm
|
import be.simplenotes.domain.usecases.register.InvalidRegisterForm
|
||||||
import be.simplenotes.domain.usecases.register.RegisterForm
|
import be.simplenotes.domain.usecases.register.RegisterForm
|
||||||
import be.simplenotes.domain.usecases.register.UserExists
|
import be.simplenotes.domain.usecases.register.UserExists
|
||||||
|
import be.simplenotes.shared.config.JwtConfig
|
||||||
import org.http4k.core.Method.GET
|
import org.http4k.core.Method.GET
|
||||||
import org.http4k.core.Request
|
import org.http4k.core.Request
|
||||||
import org.http4k.core.Response
|
import org.http4k.core.Response
|
||||||
@ -19,10 +20,12 @@ import org.http4k.core.cookie.Cookie
|
|||||||
import org.http4k.core.cookie.SameSite
|
import org.http4k.core.cookie.SameSite
|
||||||
import org.http4k.core.cookie.cookie
|
import org.http4k.core.cookie.cookie
|
||||||
import org.http4k.core.cookie.invalidateCookie
|
import org.http4k.core.cookie.invalidateCookie
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class UserController(
|
class UserController(
|
||||||
private val userService: UserService,
|
private val userService: UserService,
|
||||||
private val userView: UserView,
|
private val userView: UserView,
|
||||||
|
private val jwtConfig: JwtConfig,
|
||||||
) {
|
) {
|
||||||
fun register(request: Request, jwtPayload: JwtPayload?): Response {
|
fun register(request: Request, jwtPayload: JwtPayload?): Response {
|
||||||
if (request.method == GET) return Response(OK).html(
|
if (request.method == GET) return Response(OK).html(
|
||||||
@ -90,9 +93,7 @@ class UserController(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun Response.loginCookie(token: Token, secure: Boolean): Response {
|
private fun Response.loginCookie(token: Token, secure: Boolean): Response {
|
||||||
// FIXME: expires
|
val validityInSeconds = TimeUnit.SECONDS.convert(jwtConfig.validity, jwtConfig.timeUnit)
|
||||||
// val expiresAt = JWT.decode(token).expiresAt
|
|
||||||
// LocalDateTime.ofEpochSecond(expiresAt.time, 0)
|
|
||||||
|
|
||||||
return this.cookie(
|
return this.cookie(
|
||||||
Cookie(
|
Cookie(
|
||||||
@ -101,6 +102,7 @@ class UserController(
|
|||||||
path = "/",
|
path = "/",
|
||||||
httpOnly = true,
|
httpOnly = true,
|
||||||
sameSite = SameSite.Lax,
|
sameSite = SameSite.Lax,
|
||||||
|
maxAge = validityInSeconds,
|
||||||
secure = secure
|
secure = secure
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user