Skip to content

Instantly share code, notes, and snippets.

@fitomad

fitomad/vapor4_sesion_use.swift Secret

Created Apr 27, 2020
Embed
What would you like to do?
// MARK: - HTTP -
func routes(_ app: Application) throws {
...
///
app.post("login") { req -> HTTPStatus in
let login = try req.content.decode(LoginRequest.self)
...
// almacenamos valores en la sesion
req.session.data["nickname"] = login.nickname
req.session.data["room"] = login.roomName
...
}
}
// MARK: - WebSockets -
func webSockets(_ app: Application) throws
{
app.webSocket("chat") { request, ws in
...
// Recuperamos valores de la sesion.
let userName = request.session.data["nickname"] ?? "Usuario desconocido"
let room = request.session.data["room"] ?? "The Empty"
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.