Add backend support for login status checks

This commit is contained in:
QiTao Weng 2022-04-10 00:23:51 -05:00
parent 54dad8013b
commit 8cd1409eb6
2 changed files with 14 additions and 4 deletions

View File

@ -44,8 +44,7 @@ export class Login extends Controller {
await this.security.authenticate(user)
return redirect('/')
return api.one(user)
}
public async register() {
@ -70,6 +69,10 @@ export class Login extends Controller {
// then login
await this.security.authenticate(newUser)
return redirect('/')
return api.one(newUser)
}
public async logout() {
await this.security.flush()
}
}

View File

@ -1,4 +1,4 @@
import {Route, SessionAuthMiddleware} from '@extollo/lib'
import {Route, AuthRequiredMiddleware, GuestRequiredMiddleware, SessionAuthMiddleware} from '@extollo/lib'
import {Home} from '../controllers/main/Home.controller'
import {Login} from '../controllers/api/Login.controller'
@ -14,17 +14,24 @@ Route.group('/', () => {
Route.group('/login', () => {
Route.post('/')
.pre(GuestRequiredMiddleware)
.calls<Login>(Login, login => login.login)
Route.get('/status')
.calls<Login>(Login, login => login.status)
Route.get('/user')
.pre(AuthRequiredMiddleware)
.calls<Login>(Login, login => login.user)
})
Route.post('/register')
.pre(GuestRequiredMiddleware)
.calls<Login>(Login, login => login.register)
Route.post('/logout')
.pre(AuthRequiredMiddleware)
.calls<Login>(Login, login => login.logout)
})
}).pre(SessionAuthMiddleware)