From 40ce6e73b12561ec1b08f0ca0a12477ac20c8ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?samuel=20caliman=20gon=C3=A7alves?= Date: Mon, 23 Dec 2024 14:07:03 -0300 Subject: [PATCH 1/5] feat: add redirect optional prop to get link functions --- .../builtins/src/collections/user/getActivationLink.ts | 8 ++++++-- .../src/collections/user/getRedefinePasswordLink.ts | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/builtins/src/collections/user/getActivationLink.ts b/packages/builtins/src/collections/user/getActivationLink.ts index a252bec8..ee2d25cb 100644 --- a/packages/builtins/src/collections/user/getActivationLink.ts +++ b/packages/builtins/src/collections/user/getActivationLink.ts @@ -20,7 +20,7 @@ export const getActivationToken = async (strId: string, context: Context) => { return token } -export const getActivationLink = async (payload: { userId: ObjectId | string }, context: Context) => { +export const getActivationLink = async (payload: { userId: ObjectId | string, redirect?:string}, context: Context) => { if(!context.config.webPublicUrl){ return context.error(HTTPStatus.BadRequest, { code: ActivationError.InvalidLink, @@ -45,7 +45,11 @@ export const getActivationLink = async (payload: { userId: ObjectId | string }, const activationToken = await getActivationToken(payload.userId.toString(), context) const url = `${context.config.webPublicUrl}/user/activation?step=password&u=${payload.userId.toString()}&t=${activationToken}` - + + if(payload.redirect){ + url+payload.redirect + } + return Result.result({ url, }) diff --git a/packages/builtins/src/collections/user/getRedefinePasswordLink.ts b/packages/builtins/src/collections/user/getRedefinePasswordLink.ts index ca350333..ee8340f4 100644 --- a/packages/builtins/src/collections/user/getRedefinePasswordLink.ts +++ b/packages/builtins/src/collections/user/getRedefinePasswordLink.ts @@ -4,7 +4,7 @@ import { Result, HTTPStatus } from '@aeriajs/types' import { ActivationError } from './redefinePassword.js' import { getActivationToken } from './getActivationLink.js' -export const getRedefinePasswordLink = async (payload: { userId: ObjectId | string }, context: Context) => { +export const getRedefinePasswordLink = async (payload: { userId: ObjectId | string, redirect?:string }, context: Context) => { if(!context.config.webPublicUrl){ throw new Error('config.webPublicUrl is not set') } @@ -29,6 +29,10 @@ export const getRedefinePasswordLink = async (payload: { userId: ObjectId | stri const url = `${context.config.webPublicUrl}/user/redefine-password?step=password&u=${payload.userId.toString()}&t=${redefineToken}` + if(payload.redirect){ + url+payload.redirect + } + return Result.result({ url, }) From fb162757cceca8b2d53d24ed96264c2b6a53b072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?samuel=20caliman=20gon=C3=A7alves?= Date: Mon, 23 Dec 2024 14:08:15 -0300 Subject: [PATCH 2/5] feat: add redirect optional prop to get link functions --- packages/builtins/src/collections/user/getActivationLink.ts | 4 ++-- .../builtins/src/collections/user/getRedefinePasswordLink.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/builtins/src/collections/user/getActivationLink.ts b/packages/builtins/src/collections/user/getActivationLink.ts index ee2d25cb..6ba46f6d 100644 --- a/packages/builtins/src/collections/user/getActivationLink.ts +++ b/packages/builtins/src/collections/user/getActivationLink.ts @@ -47,9 +47,9 @@ export const getActivationLink = async (payload: { userId: ObjectId | string, re const url = `${context.config.webPublicUrl}/user/activation?step=password&u=${payload.userId.toString()}&t=${activationToken}` if(payload.redirect){ - url+payload.redirect + url+`&next=${payload.redirect}` } - + return Result.result({ url, }) diff --git a/packages/builtins/src/collections/user/getRedefinePasswordLink.ts b/packages/builtins/src/collections/user/getRedefinePasswordLink.ts index ee8340f4..7955f737 100644 --- a/packages/builtins/src/collections/user/getRedefinePasswordLink.ts +++ b/packages/builtins/src/collections/user/getRedefinePasswordLink.ts @@ -30,7 +30,7 @@ export const getRedefinePasswordLink = async (payload: { userId: ObjectId | stri const url = `${context.config.webPublicUrl}/user/redefine-password?step=password&u=${payload.userId.toString()}&t=${redefineToken}` if(payload.redirect){ - url+payload.redirect + url+`&next=${payload.redirect}` } return Result.result({ From 2e82ac01be8b77c0af6cad3e0329fba7bc5622ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?samuel=20caliman=20gon=C3=A7alves?= Date: Mon, 23 Dec 2024 19:48:45 -0300 Subject: [PATCH 3/5] feat: refactor url creation to use url constructor --- .../src/collections/user/getActivationLink.ts | 11 +++++++---- .../src/collections/user/getRedefinePasswordLink.ts | 9 +++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/builtins/src/collections/user/getActivationLink.ts b/packages/builtins/src/collections/user/getActivationLink.ts index 6ba46f6d..cf5dde0f 100644 --- a/packages/builtins/src/collections/user/getActivationLink.ts +++ b/packages/builtins/src/collections/user/getActivationLink.ts @@ -44,12 +44,15 @@ export const getActivationLink = async (payload: { userId: ObjectId | string, re const activationToken = await getActivationToken(payload.userId.toString(), context) - const url = `${context.config.webPublicUrl}/user/activation?step=password&u=${payload.userId.toString()}&t=${activationToken}` - + //const url = `${context.config.webPublicUrl}/user/activation?step=password&u=${payload.userId.toString()}&t=${activationToken}` + const url = new URL(`${context.config.webPublicUrl}/user/activation`) + url.searchParams.set("step", "password"), + url.searchParams.set("u", payload.userId.toString()) + url.searchParams.set("t", activationToken) if(payload.redirect){ - url+`&next=${payload.redirect}` + url.searchParams.set('next', payload.redirect) } - + return Result.result({ url, }) diff --git a/packages/builtins/src/collections/user/getRedefinePasswordLink.ts b/packages/builtins/src/collections/user/getRedefinePasswordLink.ts index 7955f737..58c54724 100644 --- a/packages/builtins/src/collections/user/getRedefinePasswordLink.ts +++ b/packages/builtins/src/collections/user/getRedefinePasswordLink.ts @@ -27,12 +27,13 @@ export const getRedefinePasswordLink = async (payload: { userId: ObjectId | stri const redefineToken = await getActivationToken(payload.userId.toString(), context) - const url = `${context.config.webPublicUrl}/user/redefine-password?step=password&u=${payload.userId.toString()}&t=${redefineToken}` - + const url = new URL(`${context.config.webPublicUrl}/user/activation`) + url.searchParams.set("step", "password"), + url.searchParams.set("u", payload.userId.toString()) + url.searchParams.set("t", redefineToken) if(payload.redirect){ - url+`&next=${payload.redirect}` + url.searchParams.set('next', payload.redirect) } - return Result.result({ url, }) From 126ab6211ff75913dcd2d1ee9f9098d436b96a30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?samuel=20caliman=20gon=C3=A7alves?= Date: Mon, 23 Dec 2024 20:49:49 -0300 Subject: [PATCH 4/5] chore: add changeset --- .changeset/quiet-clocks-appear.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/quiet-clocks-appear.md diff --git a/.changeset/quiet-clocks-appear.md b/.changeset/quiet-clocks-appear.md new file mode 100644 index 00000000..68aee486 --- /dev/null +++ b/.changeset/quiet-clocks-appear.md @@ -0,0 +1,5 @@ +--- +"@aeriajs/builtins": patch +--- + +feat: add optional parameter to getactivationlink and getredefinepasswordlink to redirect on success From 7e23f88c4ba658de2f763da20d34ad6845e52f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?samuel=20caliman=20gon=C3=A7alves?= Date: Fri, 27 Dec 2024 14:06:02 -0300 Subject: [PATCH 5/5] fix: fixed redefine link function creating an activation link --- .../builtins/src/collections/user/getRedefinePasswordLink.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builtins/src/collections/user/getRedefinePasswordLink.ts b/packages/builtins/src/collections/user/getRedefinePasswordLink.ts index 58c54724..a878ff2b 100644 --- a/packages/builtins/src/collections/user/getRedefinePasswordLink.ts +++ b/packages/builtins/src/collections/user/getRedefinePasswordLink.ts @@ -27,7 +27,7 @@ export const getRedefinePasswordLink = async (payload: { userId: ObjectId | stri const redefineToken = await getActivationToken(payload.userId.toString(), context) - const url = new URL(`${context.config.webPublicUrl}/user/activation`) + const url = new URL(`${context.config.webPublicUrl}/user/redefine-password`) url.searchParams.set("step", "password"), url.searchParams.set("u", payload.userId.toString()) url.searchParams.set("t", redefineToken)