1+ import Google from "@auth/core/providers/google" ;
2+ import { accounts , sessions , verificationTokens } from "./db/schema/auth" ;
13import { cors } from "hono/cors" ;
24import { db } from "./db/index" ;
5+ import { DrizzleAdapter } from "@auth/drizzle-adapter" ;
36import { env } from "./env/env" ;
47import { Hono } from "hono" ;
8+ import { initAuthConfig , verifyAuth , authHandler } from "@hono/auth-js" ;
59import { users } from "./db/schema/users" ;
610
711const app = new Hono < { Variables : { db : typeof db } } > ( ) ;
@@ -19,10 +23,35 @@ app.use(
1923 allowHeaders : [ "Content-Type" , "Authorization" ] ,
2024 allowMethods : [ "GET" , "POST" , "PUT" , "DELETE" , "OPTIONS" ] ,
2125 credentials : true ,
22- origin : "*" ,
23- } ) ,
26+ origin : "*" , // TODO: Update me!
27+ } )
2428) ;
2529
30+ // Initialize auth config
31+ app . use (
32+ "*" ,
33+ initAuthConfig ( ( ) => ( {
34+ adapter : DrizzleAdapter ( db , {
35+ accountsTable : accounts ,
36+ sessionsTable : sessions ,
37+ usersTable : users ,
38+ verificationTokensTable : verificationTokens ,
39+ } ) ,
40+ // ? - Manually add new providers here
41+ providers : [
42+ Google ( {
43+ clientId : env . GOOGLE_CLIENT_ID ,
44+ clientSecret : env . GOOGLE_CLIENT_SECRET ,
45+ } ) ,
46+ ] ,
47+ secret : env . AUTH_SECRET ,
48+ session : { strategy : "database" } ,
49+ } ) )
50+ ) ;
51+
52+ // Set up protected routes
53+ app . use ( "/api/protected/*" , verifyAuth ( ) ) ;
54+
2655app . get ( "/" , ( c ) => {
2756 return c . json ( { message : "Hello from Hono!" } ) ;
2857} ) ;
0 commit comments