chore(version): bump version to 2.12.2 and refactor password update logic
- Incremented version in package.json from 2.12.1 to 2.12.2. - Updated the UpdatePasswordPage component to utilize the new requireUser function for improved user session handling. - Refactored requireUser function to include a next parameter for redirecting after authentication failures, enhancing user experience. - Introduced a helper function getRedirectTo for cleaner redirect logic.
This commit is contained in:
@@ -1,11 +1,14 @@
|
|||||||
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
import { UpdatePasswordForm } from '@kit/auth/password-reset';
|
import { UpdatePasswordForm } from '@kit/auth/password-reset';
|
||||||
import { AuthLayoutShell } from '@kit/auth/shared';
|
import { AuthLayoutShell } from '@kit/auth/shared';
|
||||||
|
import { requireUser } from '@kit/supabase/require-user';
|
||||||
|
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||||
|
|
||||||
import { AppLogo } from '~/components/app-logo';
|
import { AppLogo } from '~/components/app-logo';
|
||||||
import pathsConfig from '~/config/paths.config';
|
import pathsConfig from '~/config/paths.config';
|
||||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
import { requireUserInServerComponent } from '~/lib/server/require-user-in-server-component';
|
|
||||||
|
|
||||||
export const generateMetadata = async () => {
|
export const generateMetadata = async () => {
|
||||||
const { t } = await createI18nServerInstance();
|
const { t } = await createI18nServerInstance();
|
||||||
@@ -24,7 +27,15 @@ interface UpdatePasswordPageProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function UpdatePasswordPage(props: UpdatePasswordPageProps) {
|
async function UpdatePasswordPage(props: UpdatePasswordPageProps) {
|
||||||
await requireUserInServerComponent();
|
const client = getSupabaseServerClient();
|
||||||
|
|
||||||
|
const result = await requireUser(client, {
|
||||||
|
next: pathsConfig.auth.passwordUpdate,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.error) {
|
||||||
|
return redirect(result.redirectTo);
|
||||||
|
}
|
||||||
|
|
||||||
const { callback } = await props.searchParams;
|
const { callback } = await props.searchParams;
|
||||||
const redirectTo = callback ?? pathsConfig.app.home;
|
const redirectTo = callback ?? pathsConfig.app.home;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "next-supabase-saas-kit-turbo",
|
"name": "next-supabase-saas-kit-turbo",
|
||||||
"version": "2.12.1",
|
"version": "2.12.2",
|
||||||
"private": true,
|
"private": true,
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@@ -30,11 +30,15 @@ type UserClaims = {
|
|||||||
* @name requireUser
|
* @name requireUser
|
||||||
* @description Require a session to be present in the request
|
* @description Require a session to be present in the request
|
||||||
* @param client
|
* @param client
|
||||||
|
* @param options
|
||||||
|
* @param options.verifyMfa
|
||||||
|
* @param options.next
|
||||||
*/
|
*/
|
||||||
export async function requireUser(
|
export async function requireUser(
|
||||||
client: SupabaseClient,
|
client: SupabaseClient,
|
||||||
options?: {
|
options?: {
|
||||||
verifyMfa?: boolean;
|
verifyMfa?: boolean;
|
||||||
|
next?: string;
|
||||||
},
|
},
|
||||||
): Promise<
|
): Promise<
|
||||||
| {
|
| {
|
||||||
@@ -60,7 +64,7 @@ export async function requireUser(
|
|||||||
return {
|
return {
|
||||||
data: null,
|
data: null,
|
||||||
error: new AuthenticationError(),
|
error: new AuthenticationError(),
|
||||||
redirectTo: SIGN_IN_PATH,
|
redirectTo: getRedirectTo(SIGN_IN_PATH, options?.next),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +79,7 @@ export async function requireUser(
|
|||||||
return {
|
return {
|
||||||
data: null,
|
data: null,
|
||||||
error: new MultiFactorAuthError(),
|
error: new MultiFactorAuthError(),
|
||||||
redirectTo: MULTI_FACTOR_AUTH_VERIFY_PATH,
|
redirectTo: getRedirectTo(MULTI_FACTOR_AUTH_VERIFY_PATH, options?.next),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,3 +112,7 @@ export class MultiFactorAuthError extends Error {
|
|||||||
super(`Multi-factor authentication required`);
|
super(`Multi-factor authentication required`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getRedirectTo(path: string, next?: string) {
|
||||||
|
return path + (next ? `?next=${next}` : '');
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user