-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style: apply lint fixes, major restructuring & guide
- Loading branch information
Showing
32 changed files
with
225 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,26 @@ | ||
// import type { TypedResponse } from 'hono' | ||
// import { streamText } from 'hono/streaming' | ||
import { type } from 'arktype' | ||
import { appFactory } from '~/factory' | ||
|
||
import { authApp } from './auth/app' | ||
import { greetRouteApp } from './greet' | ||
import { helloRouteApp } from './hello' | ||
|
||
import { appFactory } from '~/factory' | ||
import { customArktypeValidator } from '~/helpers/arktype' | ||
|
||
const app = appFactory.createApp() | ||
// $Auth - you'll need to setup Kinde environment variables. | ||
export const apiApp = appFactory.createApp() | ||
// Auth app - you'll need to setup Kinde environment variables. | ||
.route('/auth', authApp) | ||
|
||
// Disabling the streaming API because https://github.com/sst/ion/issues/63 | ||
// Simple health check route | ||
.route('/hello', helloRouteApp) | ||
|
||
// Simple greet route for arktype input validation demo | ||
.route('/greet', greetRouteApp) | ||
|
||
// ### This block contains the sample code for streaming APIs, | ||
// import type { TypedResponse } from 'hono' | ||
// import { streamText } from 'hono/streaming' | ||
|
||
// Do note that SST doesn't support Live Development for Lambda streaming API yet: https://github.com/sst/ion/issues/63 | ||
|
||
// For RPC to know the type of streamed endpoints you could manually cast it with TypedResponse 👌 | ||
// .get('/helloStream', c => streamText(c, async (stream) => { | ||
// await stream.writeln('Hello from Hono `/api/helloStream`!') | ||
// }) as Response & TypedResponse<'Hello from Hono `/api/helloStream`!'>) | ||
|
||
// Simple health check route | ||
.get('/hello', c => c.text(`Hello from Hono \`/api/hello\`! - ${Date.now()}`)) | ||
|
||
// Simple arktype input validation demo | ||
.get( | ||
'/hello/:name', | ||
customArktypeValidator('param', type({ | ||
name: 'string>0', | ||
})), | ||
async (c) => { | ||
const { name } = c.req.valid('param') | ||
return c.text(`Hello ${name}!`) | ||
}, | ||
) | ||
|
||
export { | ||
app as apiApp, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,6 @@ | ||
import type { ClaimTokenType, FlagType } from '@kinde-oss/kinde-typescript-sdk' | ||
import { env } from 'std-env' | ||
|
||
import { kindeClient } from './kindeClients' | ||
import { getSessionManager } from './sessionManager' | ||
|
||
import { appFactory } from '~/factory' | ||
|
||
const app = appFactory.createApp() | ||
.get('/health', async (c) => { | ||
return c.text('Good', 200) | ||
}) | ||
|
||
.get('/login', async (c) => { | ||
const org_code = c.req.query('org_code') | ||
const loginUrl = await kindeClient.login(getSessionManager(c), { org_code }) | ||
|
||
c.get('session').set('backToPath', c.req.query('path')) | ||
|
||
return c.redirect(loginUrl.toString()) | ||
}) | ||
|
||
.get('/register', async (c) => { | ||
const org_code = c.req.query('org_code') | ||
const registerUrl = await kindeClient.register(getSessionManager(c), { org_code }) | ||
return c.redirect(registerUrl.toString()) | ||
}) | ||
|
||
.get('/callback', async (c) => { | ||
await kindeClient.handleRedirectToApp(getSessionManager(c), new URL(c.req.url)) | ||
|
||
let backToPath = c.get('session').get('backToPath') as string || '/' | ||
if (!backToPath.startsWith('/')) | ||
backToPath = `/${backToPath}` | ||
|
||
return c.redirect(`${env.FRONTEND_URL!}${backToPath}`) | ||
}) | ||
|
||
.get('/logout', async (c) => { | ||
const logoutUrl = await kindeClient.logout(getSessionManager(c)) | ||
return c.redirect(logoutUrl.toString()) | ||
}) | ||
|
||
.get('/isAuth', async (c) => { | ||
const isAuthenticated = await kindeClient.isAuthenticated(getSessionManager(c)) // Boolean: true or false | ||
return c.json(isAuthenticated) | ||
}) | ||
|
||
.get('/profile', async (c) => { | ||
const profile = await kindeClient.getUserProfile(getSessionManager(c)) | ||
return c.json(profile) | ||
}) | ||
|
||
.get('/createOrg', async (c) => { | ||
const org_name = c.req.query('org_name')?.toString() | ||
const createUrl = await kindeClient.createOrg(getSessionManager(c), { org_name }) | ||
return c.redirect(createUrl.toString()) | ||
}) | ||
|
||
.get('/getOrg', async (c) => { | ||
const org = await kindeClient.getOrganization(getSessionManager(c)) | ||
return c.json(org) | ||
}) | ||
|
||
.get('/getOrgs', async (c) => { | ||
const orgs = await kindeClient.getUserOrganizations(getSessionManager(c)) | ||
return c.json(orgs) | ||
}) | ||
|
||
.get('/getPerm/:perm', async (c) => { | ||
const perm = await kindeClient.getPermission(getSessionManager(c), c.req.param('perm')) | ||
return c.json(perm) | ||
}) | ||
|
||
.get('/getPerms', async (c) => { | ||
const perms = await kindeClient.getPermissions(getSessionManager(c)) | ||
return c.json(perms) | ||
}) | ||
|
||
// Try: /api/auth/getClaim/aud, /api/auth/getClaim/email/id_token | ||
.get('/getClaim/:claim', async (c) => { | ||
const type = (c.req.query('type') ?? 'access_token') as ClaimTokenType | ||
if (!/^(?:access_token|id_token)$/.test(type)) | ||
return c.text('Bad request: type', 400) | ||
|
||
const claim = await kindeClient.getClaim(getSessionManager(c), c.req.param('claim'), type) | ||
return c.json(claim) | ||
}) | ||
|
||
.get('/getFlag/:code', async (c) => { | ||
const claim = await kindeClient.getFlag( | ||
getSessionManager(c), | ||
c.req.param('code'), | ||
c.req.query('default'), | ||
c.req.query('flagType') as keyof FlagType | undefined, | ||
) | ||
return c.json(claim) | ||
}) | ||
|
||
.get('/getToken', async (c) => { | ||
const accessToken = await kindeClient.getToken(getSessionManager(c)) | ||
return c.text(accessToken) | ||
}) | ||
import { authRoutesApp } from './routes' | ||
|
||
export { | ||
app as authApp, | ||
} | ||
export const authApp = appFactory.createApp() | ||
.route('', authRoutesApp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { env } from 'std-env' | ||
import type { ClaimTokenType, FlagType } from '@kinde-oss/kinde-typescript-sdk' | ||
|
||
import { appFactory } from '~/factory' | ||
import { getSessionManager } from '~/helpers/kinde' | ||
import { kindeClient } from '~/providers/auth/kinde-main' | ||
|
||
export const authRoutesApp = appFactory.createApp() | ||
.get('/health', async (c) => { | ||
return c.text('Good', 200) | ||
}) | ||
|
||
.get('/login', async (c) => { | ||
const org_code = c.req.query('org_code') | ||
const loginUrl = await kindeClient.login(getSessionManager(c), { org_code }) | ||
|
||
c.get('session').set('backToPath', c.req.query('path')) | ||
|
||
return c.redirect(loginUrl.toString()) | ||
}) | ||
|
||
.get('/register', async (c) => { | ||
const org_code = c.req.query('org_code') | ||
const registerUrl = await kindeClient.register(getSessionManager(c), { org_code }) | ||
return c.redirect(registerUrl.toString()) | ||
}) | ||
|
||
.get('/callback', async (c) => { | ||
await kindeClient.handleRedirectToApp(getSessionManager(c), new URL(c.req.url)) | ||
|
||
let backToPath = c.get('session').get('backToPath') as string || '/' | ||
if (!backToPath.startsWith('/')) | ||
backToPath = `/${backToPath}` | ||
|
||
return c.redirect(`${env.FRONTEND_URL!}${backToPath}`) | ||
}) | ||
|
||
.get('/logout', async (c) => { | ||
const logoutUrl = await kindeClient.logout(getSessionManager(c)) | ||
return c.redirect(logoutUrl.toString()) | ||
}) | ||
|
||
.get('/isAuth', async (c) => { | ||
const isAuthenticated = await kindeClient.isAuthenticated(getSessionManager(c)) // Boolean: true or false | ||
return c.json(isAuthenticated) | ||
}) | ||
|
||
.get('/profile', async (c) => { | ||
const profile = await kindeClient.getUserProfile(getSessionManager(c)) | ||
return c.json(profile) | ||
}) | ||
|
||
.get('/createOrg', async (c) => { | ||
const org_name = c.req.query('org_name')?.toString() | ||
const createUrl = await kindeClient.createOrg(getSessionManager(c), { org_name }) | ||
return c.redirect(createUrl.toString()) | ||
}) | ||
|
||
.get('/getOrg', async (c) => { | ||
const org = await kindeClient.getOrganization(getSessionManager(c)) | ||
return c.json(org) | ||
}) | ||
|
||
.get('/getOrgs', async (c) => { | ||
const orgs = await kindeClient.getUserOrganizations(getSessionManager(c)) | ||
return c.json(orgs) | ||
}) | ||
|
||
.get('/getPerm/:perm', async (c) => { | ||
const perm = await kindeClient.getPermission(getSessionManager(c), c.req.param('perm')) | ||
return c.json(perm) | ||
}) | ||
|
||
.get('/getPerms', async (c) => { | ||
const perms = await kindeClient.getPermissions(getSessionManager(c)) | ||
return c.json(perms) | ||
}) | ||
|
||
// Try: /api/auth/getClaim/aud, /api/auth/getClaim/email/id_token | ||
.get('/getClaim/:claim', async (c) => { | ||
const type = (c.req.query('type') ?? 'access_token') as ClaimTokenType | ||
if (!/^(?:access_token|id_token)$/.test(type)) | ||
return c.text('Bad request: type', 400) | ||
|
||
const claim = await kindeClient.getClaim(getSessionManager(c), c.req.param('claim'), type) | ||
return c.json(claim) | ||
}) | ||
|
||
.get('/getFlag/:code', async (c) => { | ||
const claim = await kindeClient.getFlag( | ||
getSessionManager(c), | ||
c.req.param('code'), | ||
c.req.query('default'), | ||
c.req.query('flagType') as keyof FlagType | undefined, | ||
) | ||
return c.json(claim) | ||
}) | ||
|
||
.get('/getToken', async (c) => { | ||
const accessToken = await kindeClient.getToken(getSessionManager(c)) | ||
return c.text(accessToken) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { type } from 'arktype' | ||
|
||
import { appFactory } from '~/factory' | ||
import { customArktypeValidator } from '~/middlewares/arktype' | ||
|
||
export const greetRouteApp = appFactory.createApp() | ||
.get( | ||
'', | ||
customArktypeValidator('query', type({ | ||
name: 'string>0', | ||
})), | ||
async (c) => { | ||
const { name } = c.req.valid('query') | ||
return c.text(`Hello ${name}!`) | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// This isa sample for structuring guide | ||
export const getHelloMessage = () => `Hello from Hono! - ${Date.now()}` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { appFactory } from '~/factory' | ||
|
||
import { getHelloMessage } from './hello.helper' | ||
|
||
export const helloRouteApp = appFactory.createApp() | ||
.get('', async c => c.text(getHelloMessage())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
apps/backend/src/api/auth/sessionManager.ts → apps/backend/src/helpers/kinde.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.