Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add parameter to get link function for activation and redefine password to redirect user on success #227

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-clocks-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aeriajs/builtins": patch
---

feat: add optional parameter to getactivationlink and getredefinepasswordlink to redirect on success
13 changes: 10 additions & 3 deletions packages/builtins/src/collections/user/getActivationLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -44,8 +44,15 @@ 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}`

//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.searchParams.set('next', payload.redirect)
}

return Result.result({
url,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand All @@ -27,8 +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/redefine-password`)
url.searchParams.set("step", "password"),
url.searchParams.set("u", payload.userId.toString())
url.searchParams.set("t", redefineToken)
if(payload.redirect){
url.searchParams.set('next', payload.redirect)
}
return Result.result({
url,
})
Expand Down