Skip to content
This repository was archived by the owner on Mar 19, 2025. It is now read-only.
Merged
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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@userfront/toolkit",
"version": "1.0.8",
"version": "1.0.9-alpha.0",
"description": "Bindings and components for authentication with Userfront with React, Vue, other frameworks, and plain JS + HTML",
"type": "module",
"directories": {
Expand Down
10 changes: 7 additions & 3 deletions package/src/forms/UniversalForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { log } from "../services/logging";
import { useState } from "react";
import { useSizeClass } from "../utils/hooks";
import SignUpWithPassword from "../views/SignUpWithPassword";
import { isLoggedIn } from "../models/config/guards";
import { isLoggedInAndInvalidLinkCredentials } from "../models/config/guards";

// TODO DEV-484: expand on string handling and localization, extract to
// a separate JSON file, add capability for client to pass in its own
Expand Down Expand Up @@ -527,7 +527,9 @@ const componentForStep = (state) => {
title: strings.reset.setNewPasswordTitle,
Component: SetNewPassword,
props: {
requireExistingPassword: isLoggedIn(),
requireExistingPassword: isLoggedInAndInvalidLinkCredentials(
state.context
),
},
};

Expand All @@ -536,7 +538,9 @@ const componentForStep = (state) => {
title: strings.reset.setNewPasswordTitle,
Component: SetNewPassword,
props: {
requireExistingPassword: isLoggedIn(),
requireExistingPassword: isLoggedInAndInvalidLinkCredentials(
state.context
),
isLoading: true,
},
};
Expand Down
10 changes: 9 additions & 1 deletion package/src/models/config/guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const hasNoActiveFactor = (context: AuthContext<any>) =>
// If so, we need to check if a second factor is required to log in.
export const hasLinkQueryParams = (context: AuthContext<any>) => {
// TODO better off in userfront-core?
return !!(context.query.token && context.query.uuid);
return !!(context.query?.token && context.query?.uuid);
};

export const isLoggedIn = () => {
Expand All @@ -117,6 +117,14 @@ export const isLoggedInOrHasLinkCredentials = (context: AuthContext<any>) => {
return isLoggedIn() || hasLinkQueryParams(context);
};

export const isLoggedInAndInvalidLinkCredentials = (
context: AuthContext<any>
) => {
const validQueryParams =
hasLinkQueryParams(context) && context.query?.isValid;
return isLoggedIn() && !validQueryParams;
};

export const isPasswordReset = (context: AuthContext<any>) => {
return context.config.type === "reset";
};
Expand Down