Skip to content

Commit

Permalink
Auth middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-lippert committed Dec 13, 2023
1 parent 7048a44 commit 5ceb0fa
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { API, json } from 'apis.do'
import { API, json, requiresAuth } from 'apis.do'
import webhooks from './github-webhooks.js'

const api = new API({
Expand All @@ -22,11 +22,11 @@ api.get('/favicon.ico', () => {
return new Response(null, { status: 404 })
})
api.get('/webhooks/github', webhooks)
api.get('/:message?', handler)
api.get('/:template/:templateId/:message?', handler)
api.createRoute('POST', '/api/:message?', handler)
api.createRoute('POST', '/:message?', handler)
api.createRoute('POST', '/:template/:templateId/:message?', handler)
api.get('/:message?', requiresAuth, handler)
api.get('/:template/:templateId/:message?', requiresAuth, handler)
api.createRoute('POST', '/api/:message?', requiresAuth, handler)
api.createRoute('POST', '/:message?', requiresAuth, handler)
api.createRoute('POST', '/:template/:templateId/:message?', requiresAuth, handler)

async function handler(req, env) {
async function getCompletion(options) {
Expand All @@ -42,7 +42,6 @@ async function handler(req, env) {
.catch(console.error)
}
const { user, json: data, hostname, pathSegments, query } = await env.CTX.fetch(req).then((res) => res.json())
if (!user.authenticated) return Response.redirect('/login')
let { messages, functions } = data || {}
let { n, max_tokens, model, store } = query || {}
if (!n) n = data?.n
Expand Down

0 comments on commit 5ceb0fa

Please sign in to comment.