mirror of
https://github.com/michivonah/themepark-assistant.git
synced 2025-12-23 14:36:29 +01:00
implement authentication with GitHub (Auth.js)
This commit is contained in:
parent
fd042118ad
commit
807e2dc408
5 changed files with 140 additions and 11 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { Hono } from 'hono'
|
||||
import { bearerAuth } from 'hono/bearer-auth'
|
||||
import { authHandler, initAuthConfig, verifyAuth } from '@hono/auth-js'
|
||||
import GitHub from '@auth/core/providers/github'
|
||||
import notification from './routes/notification'
|
||||
import logbook from './routes/logbook'
|
||||
import cronRouter from './jobs/cron'
|
||||
|
|
@ -7,10 +8,26 @@ import cronRouter from './jobs/cron'
|
|||
// create app
|
||||
const app = new Hono()
|
||||
|
||||
// add bearer authentication
|
||||
const token = 'insecure-token'
|
||||
// OAuth via Auth.js
|
||||
app.use('*', initAuthConfig((c) => ({
|
||||
secret: c.env.AUTH_SECRET,
|
||||
providers: [
|
||||
GitHub({
|
||||
clientId: c.env.GITHUB_ID,
|
||||
clientSecret: c.env.GITHUB_SECRET,
|
||||
})
|
||||
]
|
||||
})))
|
||||
|
||||
app.use('/*', bearerAuth({ token }))
|
||||
app.use('/auth/*', authHandler())
|
||||
|
||||
app.use('/*', verifyAuth())
|
||||
|
||||
// example endpoint
|
||||
app.get('/protected', (c) => {
|
||||
const auth = c.get('authUser')
|
||||
return c.json(auth)
|
||||
})
|
||||
|
||||
// define routes & export app
|
||||
app.route('/notification', notification)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue