diff --git a/demo/nextjs/lib/auth.ts b/demo/nextjs/lib/auth.ts index 0ec59b48..9fe77823 100644 --- a/demo/nextjs/lib/auth.ts +++ b/demo/nextjs/lib/auth.ts @@ -89,6 +89,36 @@ export const auth = betterAuth({ passkey(), bearer(), admin(), + { + id: "last-login-ip", + hooks: { + after: [ + { + matcher(context) { + return true; + }, + async handler(ctx) { + const header = ctx.headers; + const response = ctx.context.returned; + if (response instanceof Response) { + const hasSetCookie = response.headers.get("set-cookie"); + const hasSessionCookie = response.headers + .get("set-cookie") + ?.includes("session_token"); + if (hasSessionCookie) { + const ipAddress = + header?.get("x-forwarded-for") || + header?.get("cf-connecting-ip"); + if (ipAddress) { + //update the user's last login IP + } + } + } + }, + }, + ], + }, + }, ], socialProviders: { github: { diff --git a/docs/content/docs/plugins/phone-number.mdx b/docs/content/docs/plugins/phone-number.mdx index ffc4cefa..ef6fff66 100644 --- a/docs/content/docs/plugins/phone-number.mdx +++ b/docs/content/docs/plugins/phone-number.mdx @@ -92,10 +92,8 @@ to allow users to sign up using their phone number, you can pass `signUpOnVerifi export const auth = betterAuth({ plugins: [ phoneNumber({ - otp: { - sendOTP: (phoneNumber, code) => { - // Implement sending OTP code via SMS - } + sendOTP: (phoneNumber, code) => { + // Implement sending OTP code via SMS }, signUpOnVerification: { getTempEmail: (phoneNumber) => {