{"version":3,"file":"auth-helpers.mjs","names":[],"sources":["../../../src/plugins/test-utils/auth-helpers.ts"],"sourcesContent":["import type { AuthContext } from \"@better-auth/core\";\nimport { createCookieHeaders, createTestCookie } from \"./cookie-builder\";\nimport type { LoginResult, TestCookie } from \"./types\";\n\nexport function createLogin(ctx: AuthContext) {\n\treturn async (opts: { userId: string }): Promise<LoginResult> => {\n\t\t// Find the user first to avoid creating orphaned sessions\n\t\tconst user = await ctx.internalAdapter.findUserById(opts.userId);\n\t\tif (!user) {\n\t\t\tthrow new Error(`User not found: ${opts.userId}`);\n\t\t}\n\n\t\t// Create a session for the user\n\t\tconst session = await ctx.internalAdapter.createSession(opts.userId);\n\n\t\t// Create headers with cookie\n\t\tconst headers = await createCookieHeaders(ctx, session.token);\n\n\t\t// Create cookies array for browser/e2e testing\n\t\tconst cookies = await createTestCookie(ctx, session.token);\n\n\t\treturn {\n\t\t\tsession,\n\t\t\tuser,\n\t\t\theaders,\n\t\t\tcookies,\n\t\t\ttoken: session.token,\n\t\t};\n\t};\n}\n\nexport function createGetAuthHeaders(ctx: AuthContext) {\n\treturn async (opts: { userId: string }): Promise<Headers> => {\n\t\tconst session = await ctx.internalAdapter.createSession(opts.userId);\n\t\treturn createCookieHeaders(ctx, session.token);\n\t};\n}\n\nexport function createGetCookies(ctx: AuthContext) {\n\treturn async (opts: {\n\t\tuserId: string;\n\t\tdomain?: string;\n\t}): Promise<TestCookie[]> => {\n\t\tconst session = await ctx.internalAdapter.createSession(opts.userId);\n\t\treturn createTestCookie(ctx, session.token, opts.domain);\n\t};\n}\n"],"mappings":";;;AAIA,SAAgB,YAAY,KAAkB;AAC7C,QAAO,OAAO,SAAmD;EAEhE,MAAM,OAAO,MAAM,IAAI,gBAAgB,aAAa,KAAK,OAAO;AAChE,MAAI,CAAC,KACJ,OAAM,IAAI,MAAM,mBAAmB,KAAK,SAAS;EAIlD,MAAM,UAAU,MAAM,IAAI,gBAAgB,cAAc,KAAK,OAAO;AAQpE,SAAO;GACN;GACA;GACA,SARe,MAAM,oBAAoB,KAAK,QAAQ,MAAM;GAS5D,SANe,MAAM,iBAAiB,KAAK,QAAQ,MAAM;GAOzD,OAAO,QAAQ;GACf;;;AAIH,SAAgB,qBAAqB,KAAkB;AACtD,QAAO,OAAO,SAA+C;AAE5D,SAAO,oBAAoB,MADX,MAAM,IAAI,gBAAgB,cAAc,KAAK,OAAO,EAC5B,MAAM;;;AAIhD,SAAgB,iBAAiB,KAAkB;AAClD,QAAO,OAAO,SAGe;AAE5B,SAAO,iBAAiB,MADR,MAAM,IAAI,gBAAgB,cAAc,KAAK,OAAO,EAC/B,OAAO,KAAK,OAAO"}