| @@ -309,6 +309,29 @@ describe("authentication", () => { · 308 unmodified lines |
| 309 | expect(account).toBeNull(); | 309 | expect(account).toBeNull(); |
| 310 | }); | 310 | }); |
| 311 | | 311 | |
| | 312 | test("getCurrentAccount resolves anonymous identity by provider account id", async () => { |
| | 313 | const t = setup(); |
| | 314 | const session = await t.mutation(api.workspace.bootstrapAnonymousSession, {}); |
| | 315 | |
| | 316 | const providerAccountId = await t.run(async (ctx) => { |
| | 317 | const account = await ctx.db.get(session.accountId as Id<"accounts">); |
| | 318 | if (!account) { |
| | 319 | throw new Error("Expected anonymous account to exist"); |
| | 320 | } |
| | 321 | return account.providerAccountId; |
| | 322 | }); |
| | 323 | |
| | 324 | const anonymousIdentity = t.withIdentity({ |
| | 325 | subject: providerAccountId, |
| | 326 | provider: "anonymous", |
| | 327 | }); |
| | 328 | |
| | 329 | const account = await anonymousIdentity.query(api.app.getCurrentAccount, {}); |
| | 330 | expect(account).not.toBeNull(); |
| | 331 | expect(account!.provider).toBe("anonymous"); |
| | 332 | expect(account!.providerAccountId).toBe(providerAccountId); |
| | 333 | }); |
| | 334 | |
| 312 | test("getCurrentAccount prefers authenticated identity over anonymous session", async () => { | 335 | test("getCurrentAccount prefers authenticated identity over anonymous session", async () => { |
| 313 | const t = setup(); | 336 | const t = setup(); |
| 314 | const session = await t.mutation(api.workspace.bootstrapAnonymousSession, {}); | 337 | const session = await t.mutation(api.workspace.bootstrapAnonymousSession, {}); |