Skip to content

Commit

Permalink
Added support for anonymous signin (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
vijayasingam-paddle authored Sep 18, 2024
1 parent dbf2dec commit 99fd295
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 18 deletions.
16 changes: 15 additions & 1 deletion src/app/login/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { revalidatePath } from 'next/cache';
import { redirect } from 'next/navigation';

import { createClient } from '@/utils/supabase/server';

interface FormData {
Expand Down Expand Up @@ -33,3 +32,18 @@ export async function signInWithGithub() {
redirect(data.url);
}
}

export async function loginAnonymously() {
const supabase = createClient();
const { error: signInError } = await supabase.auth.signInAnonymously();
const { error: updateUserError } = await supabase.auth.updateUser({
email: `anonymous+${Date.now().toString(36)}@example.com`,
});

if (signInError || updateUserError) {
return { error: true };
}

revalidatePath('/', 'layout');
redirect('/');
}
19 changes: 18 additions & 1 deletion src/components/authentication/login-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import Image from 'next/image';
import { Button } from '@/components/ui/button';
import { login } from '@/app/login/actions';
import { login, loginAnonymously } from '@/app/login/actions';
import { useState } from 'react';
import { AuthenticationForm } from '@/components/authentication/authentication-form';
import { Separator } from '@/components/ui/separator';
import { useToast } from '@/components/ui/use-toast';

export function LoginForm() {
Expand All @@ -20,12 +21,28 @@ export function LoginForm() {
});
}

function handleAnonymousLogin() {
loginAnonymously().then((data) => {
if (data?.error) {
toast({ description: 'Something went wrong. Please try again', variant: 'destructive' });
}
});
}

return (
<form action={'#'} className={'px-6 md:px-16 pb-6 py-8 gap-6 flex flex-col items-center justify-center'}>
<Image src={'/assets/icons/logo/aeroedit-icon.svg'} alt={'AeroEdit'} width={80} height={80} />
<div className={'text-[30px] leading-[36px] font-medium tracking-[-0.6px] text-center'}>
Log in to your account
</div>
<Button onClick={() => handleAnonymousLogin()} type={'button'} variant={'secondary'} className={'w-full mt-6'}>
Log in as Guest
</Button>
<div className={'flex w-full items-center justify-center'}>
<Separator className={'w-5/12 bg-border'} />
<div className={'text-border text-xs font-medium px-4'}>or</div>
<Separator className={'w-5/12 bg-border'} />
</div>
<AuthenticationForm
email={email}
onEmailChange={(email) => setEmail(email)}
Expand Down
1 change: 0 additions & 1 deletion src/components/checkout/checkout-line-items.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { QuantityField } from '@/components/checkout/quantity-field';
import { Separator } from '@/components/ui/separator';
import { PricePreviewResponse } from '@paddle/paddle-js';
import { CheckoutEventsData } from '@paddle/paddle-js/types/checkout/events';
import { formatMoney } from '@/utils/paddle/parse-money';
import { Skeleton } from '@/components/ui/skeleton';
Expand Down
1 change: 0 additions & 1 deletion src/components/checkout/checkout-price-amount.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Skeleton } from '@/components/ui/skeleton';
import { PricePreviewResponse } from '@paddle/paddle-js';
import { CheckoutEventsData } from '@paddle/paddle-js/types/checkout/events';
import { formatMoney } from '@/utils/paddle/parse-money';

Expand Down
2 changes: 1 addition & 1 deletion src/components/checkout/checkout-price-container.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CheckoutPriceAmount } from '@/components/checkout/checkout-price-amount';
import { CheckoutEventsData } from '@paddle/paddle-js/types/checkout/events';
import { formatMoney, parseMoney } from '@/utils/paddle/parse-money';
import { formatMoney } from '@/utils/paddle/parse-money';
import { Skeleton } from '@/components/ui/skeleton';

interface Props {
Expand Down
1 change: 0 additions & 1 deletion src/components/checkout/quantity-field.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Minus, Plus } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';

interface Props {
quantity: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import Link from 'next/link';
import { Plus } from 'lucide-react';
import { Select } from '@/components/shared/select/select';

const teamMembers = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { ArrowUpRight } from 'lucide-react';

Expand Down
2 changes: 1 addition & 1 deletion src/components/dashboard/layout/sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { Album, CreditCard, Home, User } from 'lucide-react';
import { Album, CreditCard, Home } from 'lucide-react';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { cn } from '@/lib/utils';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { ArrowRight, DollarSign } from 'lucide-react';
import { ArrowRight } from 'lucide-react';
import Link from 'next/link';
import { Status } from '@/components/shared/status/status';
import { Subscription } from '@paddle/paddle-node-sdk';
import { cn } from '@/lib/utils';
import Image from 'next/image';
import { convertAmountFromLowestUnit, parseMoney } from '@/utils/paddle/parse-money';
import { parseMoney } from '@/utils/paddle/parse-money';

interface Props {
subscriptions: Subscription[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { SubscriptionHeader } from '@/components/dashboard/subscriptions/compone
import { Separator } from '@/components/ui/separator';
import { ErrorContent } from '@/components/dashboard/layout/error-content';
import { useEffect, useState } from 'react';
import { Subscription, Transaction } from '@paddle/paddle-node-sdk';
import { LoadingScreen } from '@/components/dashboard/layout/loading-screen';
import { SubscriptionDetailResponse, TransactionResponse } from '@/lib/api.types';

Expand Down
2 changes: 0 additions & 2 deletions src/components/home/header/header.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Link from 'next/link';
import { User } from '@supabase/supabase-js';
import { createClient } from '@/utils/supabase/client';
import { MouseEvent } from 'react';
import Image from 'next/image';
import { Button } from '@/components/ui/button';

Expand Down
4 changes: 2 additions & 2 deletions src/utils/supabase/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createServerClient, type CookieOptions } from '@supabase/ssr';
import { NextResponse, type NextRequest } from 'next/server';
import { type CookieOptions, createServerClient } from '@supabase/ssr';
import { type NextRequest, NextResponse } from 'next/server';

export async function updateSession(request: NextRequest) {
let response = NextResponse.next({
Expand Down
2 changes: 1 addition & 1 deletion src/utils/supabase/server-internal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createServerClient, type CookieOptions } from '@supabase/ssr';
import { type CookieOptions, createServerClient } from '@supabase/ssr';
import { cookies } from 'next/headers';

export function createClient() {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/supabase/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createServerClient, type CookieOptions } from '@supabase/ssr';
import { type CookieOptions, createServerClient } from '@supabase/ssr';
import { cookies } from 'next/headers';

export function createClient() {
Expand Down

0 comments on commit 99fd295

Please sign in to comment.