55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import { Context } from "hono";
|
|
import { authHandler, initAuthConfig, verifyAuth } from "@hono/auth-js";
|
|
import Credentials from "@auth/core/providers/credentials";
|
|
import { AuthConfig } from "@auth/core/types";
|
|
|
|
export const authConfig: AuthConfig = {
|
|
secret: process.env.AUTH_SECRET,
|
|
providers: [
|
|
Credentials({
|
|
name: "Credentials",
|
|
credentials: {
|
|
username: { label: "Username", type: "text" },
|
|
password: { label: "Password", type: "password" },
|
|
},
|
|
async authorize(credentials) {
|
|
// Add your authentication logic here
|
|
const user = { id: "1", name: "John Doe", email: "john@example.com" };
|
|
if (
|
|
credentials?.username === "john" &&
|
|
credentials?.password === "password"
|
|
) {
|
|
return user;
|
|
}
|
|
return null;
|
|
},
|
|
}),
|
|
],
|
|
session: {
|
|
strategy: "jwt",
|
|
},
|
|
callbacks: {
|
|
// async session({ session, token }) {
|
|
// session.user.id = token.sub;
|
|
// return session;
|
|
// },
|
|
async jwt({ token, user }) {
|
|
if (user) {
|
|
token.sub = user.id;
|
|
}
|
|
return token;
|
|
},
|
|
},
|
|
};
|
|
|
|
// auth.use("/api/auth/*", authHandler());
|
|
|
|
// auth.use("/api/*", verifyAuth());
|
|
|
|
// auth.get("/api/protected", (c) => {
|
|
// const auth = c.get("authUser");
|
|
// return c.json(auth);
|
|
// });
|
|
|
|
// export default auth;
|