Socket
Socket
Sign inDemoInstall

remix-auth-email-link

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remix-auth-email-link - npm Package Compare versions

Comparing version 1.5.2 to 2.0.0

18

build/index.d.ts

@@ -23,19 +23,18 @@ import type { SessionStorage } from '@remix-run/server-runtime';

/**
* The content of the magic link payload
* The content of the magic link payload. Keys are minified so that the resulting link is as short as possible.
*/
export declare type MagicLinkPayload = {
/**
* The email address used to authenticate
* Email address used to authenticate.
*/
emailAddress: string;
form: Record<string, unknown>;
e: string;
/**
* When the magic link was created, as an ISO string. This is used to check
* the email link is still valid.
* Form data received in the request.
*/
creationDate: string;
f?: Record<string, unknown>;
/**
* If it should be validated or not.
* Creation date of the magic link, as an ISO string. This is used to check
* the email link is still valid.
*/
validateSessionMagicLink: boolean;
c: number;
};

@@ -139,2 +138,3 @@ /**

private sendToken;
private createFormPayload;
private createMagicLinkPayload;

@@ -141,0 +141,0 @@ private encrypt;

@@ -156,11 +156,19 @@ "use strict";

}
createFormPayload(form) {
const formKeys = [...form.keys()];
return formKeys.length === 1
? undefined
: Object.fromEntries(formKeys
.filter((key) => key !== this.emailField)
.map((key) => [
key,
form.getAll(key).length > 1 ? form.getAll(key) : form.get(key),
]));
}
createMagicLinkPayload(emailAddress, form) {
const formPayload = this.createFormPayload(form);
return {
emailAddress,
form: Object.fromEntries([...form.keys()].map((key) => [
key,
form.getAll(key).length > 1 ? form.getAll(key) : form.get(key),
])),
creationDate: new Date().toISOString(),
validateSessionMagicLink: this.validateSessionMagicLink,
e: emailAddress,
...(formPayload && { f: formPayload }),
c: Date.now(),
};

@@ -186,2 +194,3 @@ }

async validateMagicLink(requestUrl, sessionMagicLink) {
var _a;
const linkCode = this.getMagicLinkCode(requestUrl);

@@ -192,4 +201,3 @@ const sessionLinkCode = sessionMagicLink

let emailAddress;
let linkCreationDateString;
let validateSessionMagicLink;
let linkCreationTime;
let form;

@@ -199,6 +207,6 @@ try {

const payload = JSON.parse(decryptedString);
emailAddress = payload.emailAddress;
form = payload.form;
linkCreationDateString = payload.creationDate;
validateSessionMagicLink = payload.validateSessionMagicLink;
emailAddress = payload.e;
form = (_a = payload.f) !== null && _a !== void 0 ? _a : {};
form[this.emailField] = emailAddress;
linkCreationTime = payload.c;
}

@@ -212,3 +220,3 @@ catch (error) {

}
if (validateSessionMagicLink) {
if (this.validateSessionMagicLink) {
if (!sessionLinkCode) {

@@ -221,7 +229,6 @@ throw new Error('Sign in link invalid. Please request a new one.');

}
if (typeof linkCreationDateString !== 'string') {
if (typeof linkCreationTime !== 'number') {
throw new TypeError('Sign in link invalid. Please request a new one.');
}
const linkCreationDate = new Date(linkCreationDateString);
const expirationTime = linkCreationDate.getTime() + this.linkExpirationTime;
const expirationTime = linkCreationTime + this.linkExpirationTime;
if (Date.now() > expirationTime) {

@@ -228,0 +235,0 @@ throw new Error('Magic link expired. Please request a new one.');

{
"name": "remix-auth-email-link",
"version": "1.5.2",
"version": "2.0.0",
"main": "./build/index.js",

@@ -5,0 +5,0 @@ "types": "./build/index.d.ts",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc