Skip to content

Commit

Permalink
ar(feat) signuppage:design-system
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloreale committed Feb 7, 2024
1 parent 31ef49f commit 2bd01ce
Show file tree
Hide file tree
Showing 32 changed files with 609 additions and 91 deletions.
11 changes: 6 additions & 5 deletions lib/auth/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { initUser } from '@controller';
export const authOptions: AuthOptions = {
// Configure one or more authentication providers
providers: [
GithubProvider({
clientId: process.env.GITHUB_ID as string,
clientSecret: process.env.GITHUB_SECRET as string,
}),
EmailProvider({
server: process.env.EMAIL_SERVER as string,
from: process.env.EMAIL_FROM as string,
// maxAge: 24 * 60 * 60, // How long email links are valid for (default 24h)
}),
GithubProvider({
clientId: process.env.GITHUB_ID as string,
clientSecret: process.env.GITHUB_SECRET as string,
}),
InstagramProvider({
clientId: process.env.INSTAGRAM_CLIENT_ID,
clientSecret: process.env.INSTAGRAM_CLIENT_SECRET,
Expand All @@ -35,7 +35,8 @@ export const authOptions: AuthOptions = {
}
},
},
callbacks: {},
callbacks: {
},
pages: {
// signIn: "/signin",
signOut: '/',
Expand Down
Empty file added middleware.ts
Empty file.
10 changes: 5 additions & 5 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ const nextConfig = {
},
async redirects() {
return [
{
source: '/signin',
destination: '/api/auth/signin',
permanent: false,
},
// {
// source: '/signin',
// destination: '/api/auth/signin',
// permanent: false,
// },
];
},
};
Expand Down
174 changes: 174 additions & 0 deletions public/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion public/next.svg

This file was deleted.

1 change: 0 additions & 1 deletion public/vercel.svg

This file was deleted.

2 changes: 2 additions & 0 deletions src/app/components/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// index.ts
'use client';
export { VNavBar } from './navbar-view';
export { VUserSettings } from './usersettings-view';
export { VSignIn } from './signin-view';
export { VSignUp } from './signup-view';
export { VList } from './list-view';
10 changes: 5 additions & 5 deletions src/app/components/client/navbar-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ export const VNavBar = () => {

// if (typeof session === "undefined") return <span>Loading...</span>;

if (authd)
if (!authd)
return (
<Dropdown>
<MenuButton>My account</MenuButton>
<MenuButton>Services</MenuButton>
<Menu
slotProps={{
listbox: { className: navbarStyles.navbar__menu__list },
}}
>
<MenuItem>Profile</MenuItem>
<MenuItem>Language settings</MenuItem>
<MenuItem>Log out</MenuItem>
<MenuItem>Rick and Morty</MenuItem>
<MenuItem>Image uploader</MenuItem>
<MenuItem>Image tagger</MenuItem>
</Menu>
</Dropdown>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/client/signin-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface IAuthProvider {

interface VSignInProps {
providers: IAuthProvider[];
user?: UserSchema;
user: UserSchema;
}

async function doSignOut() {
Expand Down
137 changes: 137 additions & 0 deletions src/app/components/client/signup-view.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// signup-view.ts
'use client';
import { useContext, useEffect, useRef, useState } from 'react';
import { useSession, signOut } from 'next-auth/react';
import { AuthContext } from '@state';
import { ALogIn, ALogOut } from '@actions';
import { navigate } from '@gateway';
import { UserSchema } from '@types';
import { Button } from "@atoms"
// import { ButtonView as NButton } from '@atoms/Button';

interface IAuthProvider {
id?: string;
name?: string;
}

interface VSignInProps {
providers: IAuthProvider[];
user?: UserSchema;
}

async function doSignOut() {
await signOut();
}

export const VSignUp = ({ providers, user, csrf }: VSignInProps) => {
const authContext = useContext(AuthContext);
const { data: session } = useSession();
const [isUserLoaded, loadUser] = ALogIn({});
const [, unloadUser] = ALogOut({});
const initd = useRef(false);
const prov = providers
const { authd, name } = authContext;
const [email, setEmail] = useState("");

const callbackUrl = process.env.NEXT_PUBLIC_NEXUS_BASE_PATH + process.env.NEXT_PUBLIC_NEXUS_LOGIN_REDIRECT_PATH

console.log({ prov })
if (!prov) return

// console.log({ NButton })

/* server/client isomorphism */
const coercedName = name || user?.name || user?.email;

useEffect(() => {
if (!isUserLoaded && session?.user && !initd.current) {
loadUser({
authd: true,
name: session.user.name,
avatar: session.user.image,
email: session.user.email,
});
initd.current = true;
}
}, [session, isUserLoaded, loadUser]);

const handleSignOut = async () => {
unloadUser();
await doSignOut();
};

// if (!providers) return;

// if (user || authd)
// return (
// <span>
// Welcome, {coercedName} <Button onClick={handleSignOut}>Sign out</Button>
// </span>
// )
return <div>
{Object.values(providers).map((provider) => (
<div>
{provider.type === "email" && (
<form action={provider.signinUrl} method="POST">
<input type="hidden" name="csrfToken" value={csrf} />
<label
className="section-header"
htmlFor={`input-email-for-${provider.id}-provider`}
>
Email
</label>
<input
id={`input-email-for-${provider.id}-provider`}
autoFocus
type="email"
name="email"
value={email}
placeholder="email@example.com"
required
/>
<Button id="submitButton" type="submit">
Sign in with {provider.name}
</Button>
</form>
)}
{provider.type === "oauth" && (
<form action={provider.signinUrl} method="POST">
<input type="hidden" name="csrfToken" value={csrf} />
{callbackUrl && (
<input
type="hidden"
name="callbackUrl"
value={callbackUrl}
/>
)}
<Button
type="submit"
className="Button"
>
{(
<img
loading="lazy"
height={24}
width={24}
id="provider-logo"
src={``}
/>
)}
{(
<img
loading="lazy"
height={24}
width={24}
id="provider-logo-dark"
src={``}
/>
)}
<span>Sign in with {provider.name}</span>
</Button>
</form>
)}
</div>

))}
</div>;
};
58 changes: 58 additions & 0 deletions src/app/components/client/usersettings-view.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// usersettings-view.tsx
'use client';
import { useContext, useEffect, useRef } from 'react';
import { useSession, signOut } from 'next-auth/react';
import { AuthContext } from '@state';
import {} from '@actions';
import { navigate } from '@gateway';

import { Dropdown } from '@mui/base/Dropdown';
import { MenuButton } from '@mui/base/MenuButton';
import { Menu } from '@mui/base/Menu';
import { MenuItem } from '@mui/base/MenuItem';

import navbarStyles from '@styles/components/navbar.module.css';

interface VUserSettings {
}

export const VUserSettings = () => {
const authContext = useContext(AuthContext);
const { data: session } = useSession();
const initd = useRef(false);

const { authd, name } = authContext;

useEffect(() => {
if (true) {
initd.current = true;
}
}, []);

const handleSignOut = async () => {
// unloadUser();
// await doSignOut();
};

// if (!providers) return;

// if (typeof session === "undefined") return <span>Loading...</span>;

if (!authd)
return (
<Dropdown>
<MenuButton>My account</MenuButton>
<Menu
slotProps={{
listbox: { className: navbarStyles.navbar__menu__list },
}}
>
<MenuItem>Profile</MenuItem>
<MenuItem>Language settings</MenuItem>
<MenuItem>Log out</MenuItem>
</Menu>
</Dropdown>
);

// return <button>Nav items !auth.d</button>;
};
3 changes: 2 additions & 1 deletion src/app/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// index.ts
export { TopNav } from './topnav';
export { NavBar } from './navbar';
export { SignIn } from './signin';
export { ToolBar } from './toolbar';
export { List } from './list';
14 changes: 3 additions & 11 deletions src/app/components/navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
// navbar.tsx
// signin.tsx
'use server';
import { CSignIn, CNavBar } from '@components/server';
import { SignIn } from '@components';
import styles from '@styles/list.module.css';
import navbarStyles from '@styles/components/navbar.module.css';
import { CNavBar } from '@components/server';

export const NavBar = () => {
return (
<div className={navbarStyles.navbar__wrapper}>
<CNavBar />
<SignIn />
</div>
);
return <CNavBar />;
};
2 changes: 2 additions & 0 deletions src/app/components/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// index.ts
export { CNavBar } from './navbar-controller';
export { CUserSettings } from './usersettings-controller';
export { CSignIn } from './signin-controller';
export { CSignUp } from './signup-controller';
export { CList } from './list-controller';
38 changes: 38 additions & 0 deletions src/app/components/server/signup-controller.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// signup-controller.ts
'use server';
import { cookies } from 'next/headers';
import type { UserSchema } from '@types';
import { getProviders, getCsrfToken } from 'next-auth/react';
import { VSignUp } from '@components/client';


interface ISignInProps {
user?: UserSchema;
}

interface ISignInData {
providers?: IAuthProviders[];
redirect?: {
destination?: string;
};
}

interface IAuthProviders {
id?: string;
name?: string;
}

async function getProvidersData(): Promise<ISignInData> {
const providers = (await getProviders()) as unknown as IAuthProviders[];
return { providers: providers ?? [] };
}

export const CSignUp = async ({ user }: ISignInProps) => {
cookies();
const csrf = await getCsrfToken()
const props: ISignInData = await getProvidersData()
const providers: IAuthProviders[] = props?.providers || []


return <VSignUp providers={providers} csrfToken={csrf} />
}
22 changes: 22 additions & 0 deletions src/app/components/server/usersettings-controller.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// usersettings-controller.tsx
'use server';
import type { IFeature, UserSchema } from '@types';
import { getUser } from '@gateway';
import { VUserSettings } from '@components/client';

interface INavBarData {
user: UserSchema;
}

async function getEnabledFeatures(): Promise<INavBarData> {
const user = await getUser();
const logged = !user;

return user;
}

export const CUserSettings = async () => {
const props: INavBarData = await getEnabledFeatures();
// const features: IAuthProviders[] = props?.features || [];
return <VUserSettings />;
};
7 changes: 0 additions & 7 deletions src/app/components/signin.tsx

This file was deleted.

Loading

0 comments on commit 2bd01ce

Please sign in to comment.