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.9-alpha.0",
"version": "1.0.9-alpha.1",
"description": "Bindings and components for authentication with Userfront with React, Vue, other frameworks, and plain JS + HTML",
"type": "module",
"directories": {
Expand Down
1 change: 1 addition & 0 deletions package/src/forms/UniversalForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ const componentForStep = (state) => {

// Already logged in - for forms on pages without redirect-on-load
case "alreadyLoggedIn":
case "refreshTokens":
return {
title: strings.general.welcome,
Component: AlreadyLoggedIn,
Expand Down
19 changes: 17 additions & 2 deletions package/src/models/forms/universal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ const universalMachineConfig: AuthMachineConfig = {
},
// This is a signup or login form, do shared initialization

// If there's already a user, proceed.
// If there's already a user refresh their tokens, proceed.
{
target: "alreadyLoggedIn",
target: "refreshTokens",
cond: "isLoggedIn",
},

Expand Down Expand Up @@ -397,6 +397,21 @@ const universalMachineConfig: AuthMachineConfig = {
],
},

refreshTokens: {
invoke: {
// Update the tokens
// @ts-ignore - TS doesn't infer all of the valid methods correctly
src: () => callUserfront({ method: "refresh" }),

onDone: {
target: "alreadyLoggedIn",
},
onError: {
target: "alreadyLoggedIn",
},
},
},

// This is a login or signup form, but we're already logged in.
// Show a message, and redirect if config.redirectOnLoad !== false.
alreadyLoggedIn: {
Expand Down
6 changes: 5 additions & 1 deletion package/src/services/userfront.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export const overrideUserfrontSingleton = (newSingleton: any) => {

// A type with the keys of all functions in Type
type Functions<Type> = {
[Key in keyof Type]-?: Type[Key] extends Function ? Key : never;
[Key in keyof Type]-?: Type[Key] extends Function
? Key
: Type[Key] extends object
? Functions<Type[Key]> // Recursively check nested objects
: never;
}[keyof Type];

export interface CallUserfront {
Expand Down