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

[DEV-1438] If the redirect parameter is set always use it as the redirect path #113

Merged
merged 2 commits into from
Jul 24, 2024
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.9",
"version": "1.0.10-alpha.0",
"description": "Bindings and components for authentication with Userfront with React, Vue, other frameworks, and plain JS + HTML",
"type": "module",
"directories": {
Expand Down
18 changes: 16 additions & 2 deletions package/src/models/config/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,28 @@ export const markAsSecondFactor = assign({
// Redirect to the afterLoginPath etc. after signed in, just an alias for the Userfront API method
export const redirectIfLoggedIn = (context: AuthContext<any>) => {
if (context.config.redirect !== false) {
callUserfront({ method: "redirectIfLoggedIn", args: [] });
callUserfront({
method: "redirectIfLoggedIn",
args: [
{
redirect: context.config?.redirect,
},
],
});
}
};

// Redirect to the afterLoginPath if the user is already logged in when the form loads, if redirectOnLoad = true
export const redirectOnLoad = (context: AuthContext<any>) => {
if (context.config.redirectOnLoad) {
callUserfront({ method: "redirectIfLoggedIn", args: [] });
callUserfront({
method: "redirectIfLoggedIn",
args: [
{
redirect: context.config?.redirect,
},
],
});
}
};

Expand Down
2 changes: 2 additions & 0 deletions package/src/models/forms/universal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ const universalMachineConfig: AuthMachineConfig = {
args: [
{
method: event.factor?.strategy,
redirect: context.config?.redirect,
},
],
});
Expand All @@ -695,6 +696,7 @@ const universalMachineConfig: AuthMachineConfig = {
method: "link",
token: context.query.token,
uuid: context.query.uuid,
redirect: context.config?.redirect,
},
],
});
Expand Down
5 changes: 3 additions & 2 deletions package/src/models/views/emailLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const emailLinkConfig: AuthMachineConfig = {
});
}
// Login link
const arg: Record<string, any> = {
const arg: Record<string, string | boolean | undefined> = {
method: "passwordless",
email: context.user.email,
redirect: context.config.redirect,
Expand Down Expand Up @@ -86,9 +86,10 @@ const emailLinkConfig: AuthMachineConfig = {
invoke: {
// Set the method and email, and name and/or username if present, as arguments
src: (context) => {
const arg: Record<string, string> = {
const arg: Record<string, string | boolean | undefined> = {
method: "passwordless",
email: context.user.email,
redirect: context.config.redirect,
};
if (hasValue(context.user.name)) {
arg.name = context.user.name;
Expand Down
Loading