File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
packages/better-auth/src/plugins/haveibeenpwned Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { APIError } from "../../api";
2
2
import { createHash } from "@better-auth/utils/hash" ;
3
3
import { betterFetch } from "@better-fetch/fetch" ;
4
4
import type { BetterAuthPlugin } from "../../types" ;
5
+ import { createAuthMiddleware } from "../../api" ;
5
6
6
7
const ERROR_CODES = {
7
8
PASSWORD_COMPROMISED :
@@ -63,6 +64,24 @@ export interface HaveIBeenPwnedOptions {
63
64
export const haveIBeenPwned = ( options ?: HaveIBeenPwnedOptions ) =>
64
65
( {
65
66
id : "haveIBeenPwned" ,
67
+ hooks : {
68
+ before : [
69
+ {
70
+ matcher ( ctx ) {
71
+ return ctx . path === "/sign-up/email" ;
72
+ } ,
73
+ handler : createAuthMiddleware ( async ( ctx ) => {
74
+ if ( ctx . body ?. password ) {
75
+ await checkPasswordCompromise (
76
+ ctx . body . password ,
77
+ options ?. customPasswordCompromisedMessage ,
78
+ ) ;
79
+ }
80
+ return ctx ;
81
+ } ) ,
82
+ } ,
83
+ ] ,
84
+ } ,
66
85
init ( ctx ) {
67
86
return {
68
87
context : {
You can’t perform that action at this time.
0 commit comments