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

EC-002: Login email flow #4

Merged
merged 1 commit into from
Feb 8, 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
9 changes: 5 additions & 4 deletions src/app/components/client/signup-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const VSignUp = ({ providers, user, csrf }: VSignUpProps) => {
}, [session, isUserLoaded, loadUser]);

const handleSignIn = async (id?: string, value?: SignInOptions) => {
console.log({ value })
await doSignIn(id, value);
};

Expand All @@ -88,8 +89,8 @@ export const VSignUp = ({ providers, user, csrf }: VSignUpProps) => {

return <section className={classes}>
<div>
<form action={defaultP.signinUrl} method="POST">
<Input type="hidden" name="csrfToken" value={csrf} />
<form action={defaultP.signinUrl} method="post">
<input type="hidden" name="csrfToken" defaultValue={csrf} />
<Input
id={`input-email-for-${defaultP.id}-provider`}
autoFocus
Expand All @@ -100,7 +101,7 @@ export const VSignUp = ({ providers, user, csrf }: VSignUpProps) => {
placeholder="Your email"
required
/>
<Button id="submitButton" type="submit" onClick={() => handleSignIn("email", { email })}>
<Button id="submitButton" type="submit">
Continue
</Button>
</form>
Expand All @@ -110,7 +111,7 @@ export const VSignUp = ({ providers, user, csrf }: VSignUpProps) => {
<div>
{provider.type === "email" && (
<form action={defaultP.signinUrl} method="POST">
<Input type="hidden" name="csrfToken" value={csrf} />
<input name="csrfToken" type="hidden" defaultValue={csrf} />
<Input
id={`input-email-for-${provider.id}-provider`}
autoFocus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ const classes = clsx({

export const NVButton = ({ children, onClick, variant, theme, icon, ...regularHtmlProps }: VButtonProps) => {
/* remember server/client isomorphism */
return <Button className={classes} {...regularHtmlProps} onClick={onClick}>{children}</Button>;
return <Button className={classes} {...regularHtmlProps}>{children}</Button>;
};
5 changes: 3 additions & 2 deletions src/app/components/system/atoms/input/client/input-view.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @atoms/button-view.tsx
'use client';
import type { TpositionX, Tthemes } from "@types"
import { Input } from "@mui/base/Input"
import { useInput } from '@mui/base/useInput';
import { debounce } from "@helpers"
import { clsx } from "clsx"
import styles from "./input.module.css"
Expand All @@ -20,6 +20,7 @@ interface VInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
}

export const NVInput = ({ children, onChange, value, ...regularHtmlProps }: VInputProps) => {
const { getRootProps } = useInput()
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if(onChange) {
onChange(e.target.value)
Expand All @@ -34,5 +35,5 @@ export const NVInput = ({ children, onChange, value, ...regularHtmlProps }: VInp
[styles.nexus__input]: regularHtmlProps.type !== "hidden",
})
/* remember server/client isomorphism */
return <Input className={classes} {...regularHtmlProps} onChange={dbHandleChange} >{children}</Input>;
return <input className={classes} {...getRootProps()} {...regularHtmlProps} onChange={dbHandleChange} >{children}</input>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
margin-bottom: 16px;
}

.nexus__input input {
input.nexus__input {
height: 100%;
width: 100%;
padding: 8px 16px;
Expand Down
7 changes: 5 additions & 2 deletions src/app/signin/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// signin/page.tsx TS-Doc?
'use server';
import { getProviders } from 'next-auth/react';
import { getProviders, getCsrfToken } from 'next-auth/react';
import { getServerSession } from 'next-auth/next';
import { redirect } from 'next/navigation';
import { cookies } from 'next/headers';
import { authOptions } from '@auth';
import { VSignUp } from '@components/client';
import styles from '@styles/page.module.css';
Expand Down Expand Up @@ -37,11 +38,13 @@ async function getProvidersData(): Promise<ISignInData> {
export default async function SignUp() {
const props: ISignInData = await getProvidersData();
const providers: IAuthProviders[] = props?.providers || [];
cookies();
const csrf: string | undefined = await getCsrfToken();
return (
<main className={styles.main}>
<article>
<img className={styles.logo} src="/logo.svg" />
<VSignUp providers={providers} />
<VSignUp providers={providers} csrf={csrf} />
</article>
</main>
);
Expand Down
Loading