Skip to content

Commit

Permalink
fix: Fixed useless "&" char on createEmailRedirectionLink function (#363
Browse files Browse the repository at this point in the history
)

* fix: Fixed useless & on createEmailRedirectionLink function

* chore: add changeset

---------

Co-authored-by: Szilárd Dóró <[email protected]>
  • Loading branch information
kwiky and szilarddoro committed Jun 19, 2023
1 parent 7a07b50 commit 1706c37
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-ways-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'hasura-auth': patch
---

fix(redirect): generate valid redirection links
13 changes: 7 additions & 6 deletions src/utils/redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ export const createEmailRedirectionLink = (
type: EmailType,
ticket: string,
redirectTo: string
) =>
`${
ENV.AUTH_SERVER_URL
}/verify?&ticket=${ticket}&type=${type}&redirectTo=${encodeURIComponent(
redirectTo
)}`;
): string => {
const url = new URL(`${ENV.AUTH_SERVER_URL}/verify`)
url.searchParams.set('ticket', ticket)
url.searchParams.set('type', type)
url.searchParams.set('redirectTo', redirectTo)
return url.toString()
};
16 changes: 16 additions & 0 deletions test/utils/redirect.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createEmailRedirectionLink } from '@/utils';
import { EmailType, EMAIL_TYPES } from '@/types';
import { v4 as uuidv4 } from 'uuid';
import { ENV } from '@/utils';

describe('utils', () => {
it('should create email redirection link', () => {
const ticket = `${EMAIL_TYPES.PASSWORD_RESET}:${uuidv4()}`;
const type: EmailType = EMAIL_TYPES.PASSWORD_RESET;
const redirectTo = "https://hasura.io/";

const url = createEmailRedirectionLink(type, ticket, redirectTo);

expect(url).toBe(`${ENV.AUTH_SERVER_URL}/verify?ticket=${encodeURIComponent(ticket)}&type=${encodeURIComponent(type)}&redirectTo=${encodeURIComponent(redirectTo)}`);
});
});

0 comments on commit 1706c37

Please sign in to comment.