test(auth): work on auth login and signup
This commit is contained in:
@@ -3,8 +3,10 @@ import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
||||
import {
|
||||
admin,
|
||||
apiKey,
|
||||
createAuthMiddleware,
|
||||
customSession,
|
||||
jwt,
|
||||
lastLoginMethod,
|
||||
username,
|
||||
} from "better-auth/plugins";
|
||||
import { eq } from "drizzle-orm";
|
||||
@@ -38,7 +40,7 @@ export const auth = betterAuth({
|
||||
},
|
||||
lastLogin: {
|
||||
type: "date",
|
||||
required: false,
|
||||
required: true,
|
||||
input: false,
|
||||
},
|
||||
},
|
||||
@@ -47,6 +49,7 @@ export const auth = betterAuth({
|
||||
jwt({ jwt: { expirationTime: "1h" } }),
|
||||
apiKey(),
|
||||
admin(),
|
||||
lastLoginMethod(),
|
||||
username({
|
||||
minUsernameLength: 5,
|
||||
usernameValidator: (username) => {
|
||||
@@ -119,12 +122,22 @@ export const auth = betterAuth({
|
||||
secure: false,
|
||||
httpOnly: true,
|
||||
},
|
||||
hooks: {
|
||||
after: createAuthMiddleware(async (ctx) => {
|
||||
if (ctx.path.startsWith("/login")) {
|
||||
const newSession = ctx.context.newSession;
|
||||
if (newSession) {
|
||||
// something here later
|
||||
}
|
||||
}
|
||||
}),
|
||||
},
|
||||
events: {
|
||||
async onSignInSuccess({ user }: { user: User }) {
|
||||
await db
|
||||
.update(rawSchema.user)
|
||||
.set({ lastLogin: new Date() })
|
||||
.where(eq(schema.user.id, user.id));
|
||||
},
|
||||
// async onSignInSuccess({ user }: { user: User }) {
|
||||
// await db
|
||||
// .update(rawSchema.user)
|
||||
// .set({ lastLogin: new Date() })
|
||||
// .where(eq(schema.user.id, user.id));
|
||||
// },
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user