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

Add civic auth #778

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
17 changes: 0 additions & 17 deletions .env.example

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ yarn-error.log*
# turbo
.turbo

.env*.local
.env

.vercel
.vscode
.env*.local
84 changes: 0 additions & 84 deletions app/(auth)/actions.ts

This file was deleted.

3 changes: 3 additions & 0 deletions app/(auth)/api/auth/[...civicauth]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { handler } from '@civic/auth/nextjs'

export const GET = handler()
1 change: 0 additions & 1 deletion app/(auth)/api/auth/[...nextauth]/route.ts

This file was deleted.

39 changes: 0 additions & 39 deletions app/(auth)/auth.config.ts

This file was deleted.

55 changes: 0 additions & 55 deletions app/(auth)/auth.ts

This file was deleted.

58 changes: 7 additions & 51 deletions app/(auth)/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,66 +1,22 @@
'use client';

import Link from 'next/link';
import { useRouter } from 'next/navigation';
import { useActionState, useEffect, useState } from 'react';
import { toast } from 'sonner';

import { AuthForm } from '@/components/auth-form';
import { SubmitButton } from '@/components/submit-button';

import { login, type LoginActionState } from '../actions';
import { useEffect, } from 'react';
import { CivicAuthIframeContainer, useUser } from "@civic/auth/react";

export default function Page() {
const router = useRouter();

const [email, setEmail] = useState('');
const [isSuccessful, setIsSuccessful] = useState(false);

const [state, formAction] = useActionState<LoginActionState, FormData>(
login,
{
status: 'idle',
},
);
const { user } = useUser();

useEffect(() => {
if (state.status === 'failed') {
toast.error('Invalid credentials!');
} else if (state.status === 'invalid_data') {
toast.error('Failed validating your submission!');
} else if (state.status === 'success') {
setIsSuccessful(true);
router.refresh();
if (user) {
router.push('/');
}
}, [state.status, router]);

const handleSubmit = (formData: FormData) => {
setEmail(formData.get('email') as string);
formAction(formData);
};
}, [user, router]);

return (
<div className="flex h-dvh w-screen items-start pt-12 md:pt-0 md:items-center justify-center bg-background">
<div className="w-full max-w-md overflow-hidden rounded-2xl flex flex-col gap-12">
<div className="flex flex-col items-center justify-center gap-2 px-4 text-center sm:px-16">
<h3 className="text-xl font-semibold dark:text-zinc-50">Sign In</h3>
<p className="text-sm text-gray-500 dark:text-zinc-400">
Use your email and password to sign in
</p>
</div>
<AuthForm action={handleSubmit} defaultEmail={email}>
<SubmitButton isSuccessful={isSuccessful}>Sign in</SubmitButton>
<p className="text-center text-sm text-gray-600 mt-4 dark:text-zinc-400">
{"Don't have an account? "}
<Link
href="/register"
className="font-semibold text-gray-800 hover:underline dark:text-zinc-200"
>
Sign up
</Link>
{' for free.'}
</p>
</AuthForm>
<CivicAuthIframeContainer />
</div>
</div>
);
Expand Down
70 changes: 0 additions & 70 deletions app/(auth)/register/page.tsx

This file was deleted.

Loading