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

fix: Minor login improvements #322

Merged
merged 1 commit into from
Aug 21, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface Props {
/** A form with a centered box. Ex: Login, Signup */
export function CenteredBoxForm({ children }: Props) {
return (
<div className="m-auto rounded-xl w-full max-w-sm sm:shadow-md dark:sm:shadow-slate-600 p-8 my-4 lg:my-16 mx-8 lg:mx-auto">
<div className="m-auto rounded-xl w-full max-w-sm sm:shadow-md dark:sm:shadow-slate-600 p-8 my-4 lg:my-16 lg:mx-auto">
{children}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useState } from 'react';
import { signIn } from 'next-auth/react';
import { useForm } from 'react-hook-form';
import NextLink from 'next/link';
import { useRouter } from 'next/router';
import Link from 'next/link';

Expand Down Expand Up @@ -91,11 +90,11 @@ export function LoginForm() {
</PasswordField>
</div>
<div className="flex justify-between">
<NextLink href="/reset-password">
<Button variant="link" size="sm">
Comment on lines -94 to -95
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think NextLink is necessary anymore. I'm also not seeing it in the "pages" docs

<Link href="/reset-password">
<Button variant="link" size="sm" type="button">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user hits enter on their keyboard, it redirected them to /reset-password instead of signing in. The workaround is having type=button attribute. This is necessary when there are multiple buttons in a form.

Forgot password?
</Button>
</NextLink>
</Link>
</div>
<div className="flex gap-6 flex-col">
<Button variant="outline" type="submit" disabled={loading} data-testid="login-submit">
Expand Down
6 changes: 1 addition & 5 deletions packages/create-bison-app/template/src/layouts/LoggedIn.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ReactNode } from 'react';
import { useRouter } from 'next/router';
import { signOut } from 'next-auth/react';

import { Logo } from '@/components/Logo';
Expand All @@ -12,11 +11,8 @@ interface Props {
}

export function LoggedInLayout({ children }: Props) {
const router = useRouter();

async function handleLogout() {
signOut();
await router.replace('/login');
Copy link
Contributor Author

@dennis-campos dennis-campos Jul 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caused a flash to /login page and redirected the user back to /

await signOut({ callbackUrl: '/login' });
}

return (
Expand Down