Start api

This commit is contained in:
Garrett Mills 2022-04-09 13:02:44 -05:00
parent bc4a4224de
commit 662ba0aa3d
7 changed files with 70 additions and 26 deletions

12
.idea/dataSources.xml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="mathy@localhost" uuid="d7b1325c-41d2-4d9e-9728-88db6eeedda2">
<driver-ref>postgresql</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.postgresql.Driver</jdbc-driver>
<jdbc-url>jdbc:postgresql://localhost:5432/mathy</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

View File

@ -1,5 +1,5 @@
import { env } from '@extollo/lib'
export default {
name: env('APP_NAME', 'Extollo'),
name: env('APP_NAME', 'Mathy'),
}

View File

@ -1,21 +1,8 @@
import {AuthenticationConfig, CoreIDLoginProvider, OAuth2LoginProviderConfig, ORMUserRepository, env} from '@extollo/lib'
import {AuthenticationConfig, ORMUserRepository} from '@extollo/lib'
const authConfig: AuthenticationConfig = {
storage: ORMUserRepository,
providers: {
coreid: {
driver: CoreIDLoginProvider,
config: {
default: true,
displayName: 'Starship CoreID',
clientId: env('COREID_CLIENT_ID'),
clientSecret: env('COREID_CLIENT_SECRET'),
loginUrl: env('COREID_BASE', '') + '/auth/service/oauth2/authorize?client_id=%c&redirect_uri=%r',
tokenUrl: env('COREID_BASE', '') + '/auth/service/oauth2/redeem',
userUrl: env('COREID_BASE', '') + '/api/v1/auth/users/me',
} as OAuth2LoginProviderConfig,
}
},
providers: {},
}
export default authConfig

View File

@ -6,9 +6,9 @@ import {
LocalFilesystemConfig,
RedisCache,
CacheQueue,
BusConnectorConfig, QueueConfig, SyncQueue
BusConnectorConfig,
QueueConfig,
} from "@extollo/lib"
import {LogRequest} from "../http/middlewares/LogRequest.middleware";
export default {
debug: env('DEBUG_MODE', false),
@ -60,7 +60,7 @@ export default {
middleware: {
global: {
pre: [LogRequest],
pre: [],
},
},
}

View File

@ -0,0 +1,32 @@
import {Controller, view, Inject, Injectable, SecurityContext, api} from '@extollo/lib'
import {User} from '../../../models/User.model'
/**
* Login Controller
* ------------------------------------
* API routes related to logging users into the application.
*/
@Injectable()
export class Login extends Controller {
@Inject()
protected readonly security!: SecurityContext
public status() {
return api.one({
hasUser: this.security.hasUser(),
})
}
public user() {
const user = this.security.getUser()
if ( !user ) {
return api.error('There is no user authenticated.')
}
return api.one(user)
}
public async callbackFromAuth0() {
return api.error('Implement me!')
}
}

View File

@ -14,7 +14,7 @@ export class Home extends Controller {
const valid = new Promise<UserLogin>(() => {})
return view('@extollo:welcome', {
return view('welcome', {
app_visits: this.session.get('app_visits'),
locale: this.locale.helper(),
})

View File

@ -1,13 +1,26 @@
import {Route, SessionAuthMiddleware, AuthRequiredMiddleware} from '@extollo/lib'
import {Route, SessionAuthMiddleware} from '@extollo/lib'
import {Home} from '../controllers/main/Home.controller'
import {Login} from '../controllers/api/Login.controller'
Route.group('/', () => {
Route.get('/')
.calls<Home>(Home, home => home.welcome)
})
Route.group('', () => {
Route.get('/dash')
.pre(AuthRequiredMiddleware)
.calls<Home>(Home, home => home.welcome)
Route.group('/api', () => {
Route.get('/')
.handledBy(() => ({
success: true,
}))
Route.group('/login', () => {
Route.get('/status')
.calls<Login>(Login, login => login.status)
Route.get('/user')
.calls<Login>(Login, login => login.user)
Route.post('/user')
.calls<Login>(Login, login => login.callbackFromAuth0)
})
})
}).pre(SessionAuthMiddleware)