Skip to content

Commit

Permalink
revert maigc link
Browse files Browse the repository at this point in the history
  • Loading branch information
nichtsam committed Jan 28, 2025
1 parent 117dabf commit 0e7f10d
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 1,487 deletions.
11 changes: 3 additions & 8 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# set this to true to prevent search engines from indexing the website
# default to false for seo safety
DISALLOW_INDEXING="false"

# generate with `openssl rand -hex 32`
SESSION_SECRET="session_secret"
CSRF_SECRET="csrf_secret"
MAGIC_LINK_SECRET="magic_link_secret"

# Github > Settings > Developer settings > New App
# or simply https://github.com/settings/developers
Expand All @@ -23,9 +18,9 @@ TURSO_DB_URL="file:local/dev.db"
# turso db tokens create <database-name>
TURSO_DB_AUTH_TOKEN="MOCK_TURSO_DB_AUTH_TOKEN"

# Resend > API Keys > Create API Key
# https://resend.com/api-keys
RESEND_API_KEY="MOCK_RESEND_API_KEY"
# set this to true to prevent search engines from indexing the website
# default to false for seo safety
DISALLOW_INDEXING="false"

# Sentry > Project Setting > SDK Setup > Client Keys
SENTRY_DNS="your-dns"
48 changes: 0 additions & 48 deletions app/components/emails/magic-link.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion app/components/status-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface StatusButtonProps extends ButtonProps {
export const StatusButton = forwardRef<HTMLButtonElement, StatusButtonProps>(
({ status, className, children, ...props }, ref) => {
const statusIcon = {
success: <Icon name="check-circled" className="text-green-600" />,
success: <Icon name="check-circled" />,
pending: <Icon name="update" className="animate-spin" />,
error: (
<Icon
Expand Down
29 changes: 0 additions & 29 deletions app/components/ui/separator.tsx

This file was deleted.

92 changes: 0 additions & 92 deletions app/routes/_auth+/auth.magic.tsx

This file was deleted.

83 changes: 1 addition & 82 deletions app/routes/_auth+/login.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
import { getFormProps, getInputProps, useForm } from '@conform-to/react'
import { getZodConstraint, parseWithZod } from '@conform-to/zod'
import { type SEOHandle } from '@nasa-gcn/remix-seo'
import { data, Form, useActionData, useSearchParams } from 'react-router'
import { z } from 'zod'
import { Field } from '#app/components/forms.tsx'
import { StatusButton } from '#app/components/status-button.tsx'
import { useSearchParams } from 'react-router'
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '#app/components/ui/card.tsx'
import { Separator } from '#app/components/ui/separator.tsx'
import { requireAnonymous } from '#app/utils/auth/auth.server.ts'
import {
ProviderConnectionForm,
providerNames,
} from '#app/utils/auth/connections.tsx'
import { createAuthenticator } from '#app/utils/auth/magic-link.server.ts'
import { combineHeaders } from '#app/utils/request.server.ts'
import { createToastHeaders } from '#app/utils/toast.server.ts'
import { useIsPending } from '#app/utils/ui.ts'
import { type Route } from './+types/login'

export const handle: SEOHandle = {
Expand All @@ -44,37 +34,6 @@ export async function loader({ request }: Route.LoaderArgs) {
return null
}

export async function action({ request }: Route.ActionArgs) {
const formData = await request.clone().formData()
const submission = parseWithZod(formData, {
schema: MagicLinkLoginSchema,
})

if (submission.status !== 'success') {
return data(
{ result: submission.reply() },
{ status: submission.status === 'error' ? 400 : 200 },
)
}

const authenticator = createAuthenticator(request)
const authHeaders = (await authenticator
.authenticate('email-link', request)
.catch((headers) => headers)) as Headers

const toastHeaders = await createToastHeaders({
title: '✨ Magic Link has been sent',
message: `sent to ${submission.value.email}`,
})

return data(
{ result: submission.reply() },
{
headers: combineHeaders(authHeaders, toastHeaders),
},
)
}

export default function Login() {
const [searchParams] = useSearchParams()
const redirectTo = searchParams.get('redirectTo')
Expand All @@ -87,8 +46,6 @@ export default function Login() {
<CardDescription>Choose your path</CardDescription>
</CardHeader>
<CardContent>
<MagicLinkLogin />
<Separator className="my-4" />
<ul className="flex flex-col gap-y-2">
{providerNames.map((providerName) => (
<li key={providerName}>
Expand All @@ -104,41 +61,3 @@ export default function Login() {
</div>
)
}

export const MagicLinkLoginSchema = z.object({
email: z.string().email(),
})

function MagicLinkLogin() {
const isPending = useIsPending()
const actionData = useActionData<typeof action>()
const [form, fields] = useForm({
id: 'magic-link-login-form',
constraint: getZodConstraint(MagicLinkLoginSchema),
lastResult: actionData?.result,
shouldRevalidate: 'onBlur',
onValidate: ({ formData }) =>
parseWithZod(formData, { schema: MagicLinkLoginSchema }),
})

return (
<Form method="post" {...getFormProps(form)}>
<Field
labelProps={{ children: 'Email' }}
inputProps={{
...getInputProps(fields.email, { type: 'email' }),
autoComplete: 'email',
}}
errors={fields.email.errors}
/>
<StatusButton
type="submit"
className="w-full"
status={isPending ? 'pending' : (form.status ?? 'idle')}
disabled={isPending}
>
Email a login link
</StatusButton>
</Form>
)
}
24 changes: 0 additions & 24 deletions app/utils/auth/magic-link.server.ts

This file was deleted.

34 changes: 0 additions & 34 deletions app/utils/email.server.tsx

This file was deleted.

Loading

0 comments on commit 0e7f10d

Please sign in to comment.