Skip to content

Commit

Permalink
fix: invitation link for new session should be get http verb
Browse files Browse the repository at this point in the history
  • Loading branch information
TruffeCendree committed Nov 13, 2021
1 parent 4f178a9 commit 0446d97
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/mailers/session-mailer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function sendInvitation(user: User) {
Hello ${user.firstname},
Use the above link to login on the peer review app for the practical activity.
${BASE_URL}/?token=${user.loginToken}
${BASE_URL}/sessions/establish?token=${user.loginToken}
This link works only once, but can be renewed multiple times.
Expand Down
6 changes: 3 additions & 3 deletions src/routes/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { randomBytes } from 'crypto'
import { sendInvitation } from '../mailers/session-mailer'

export async function sessionRoutes(fastify: FastifyInstance) {
fastify.post<{ Querystring: SessionsCreateQuerystring }>('/', {
fastify.get<{ Querystring: SessionsCreateQuerystring }>('/establish', {
schema: {
querystring: sessionsCreateQuerystringSchema
},
handler: async function create(request, reply) {
handler: async function establish(request, reply) {
// should be handled by the schema validation, but is too critical so we check it again.
if (!request.query.token) throw new Error('Never lookup for a null loginToken, it will match the wrong user.')

Expand All @@ -34,7 +34,7 @@ export async function sessionRoutes(fastify: FastifyInstance) {
},
handler: async function invite(request) {
const user = await getRepository(User).findOneOrFail({ where: { email: request.body.email } })
user.loginToken = (await promisify(randomBytes)(64)).toString('base64')
user.loginToken = (await promisify(randomBytes)(64)).toString('hex')
await getRepository(User).save(user)
await sendInvitation(user)
return { success: true }
Expand Down

0 comments on commit 0446d97

Please sign in to comment.