Samuel Shuert | 341d4a6 | 2024-02-04 14:51:12 -0500 | [diff] [blame] | 1 | import NextAuth, { type AuthOptions } from "next-auth" |
Samuel Shuert | f4deb4e | 2024-02-04 13:56:30 -0500 | [diff] [blame] | 2 | import KeycloakProvider from "next-auth/providers/keycloak"; |
Samuel Shuert | 341d4a6 | 2024-02-04 14:51:12 -0500 | [diff] [blame] | 3 | import { DrizzleAdapter } from "@auth/drizzle-adapter"; |
| 4 | import { db } from "@/db" |
Samuel Shuert | f4deb4e | 2024-02-04 13:56:30 -0500 | [diff] [blame] | 5 | |
| 6 | let getSecrets = () => { |
| 7 | let clientId = process.env.CLIENT_ID; |
| 8 | let clientSecret = process.env.CLIENT_SECRET; |
| 9 | |
| 10 | if (!clientId || !clientSecret) throw new Error("Missing Client Environment Vars"); |
| 11 | return {clientId, clientSecret} |
| 12 | } |
| 13 | |
Samuel Shuert | 341d4a6 | 2024-02-04 14:51:12 -0500 | [diff] [blame] | 14 | export const authOptions: AuthOptions = { |
| 15 | adapter: DrizzleAdapter(db), // IDK how to get this to not TS error. Followed Docs word for word |
Samuel Shuert | f4deb4e | 2024-02-04 13:56:30 -0500 | [diff] [blame] | 16 | providers: [ |
| 17 | KeycloakProvider(Object.assign(getSecrets(), { |
| 18 | issuer: "https://`login.clicks.codes/realms/master" |
| 19 | })), |
| 20 | ], |
| 21 | } |
| 22 | |
| 23 | |
| 24 | const handler = NextAuth(authOptions) |
| 25 | |
| 26 | export { handler as GET, handler as POST } |