forked from lmsqueezy/nextjs-billing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
140 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
import { getSession } from "@/lib/auth"; | ||
import Link from 'next/link' | ||
|
||
export default function Home() { | ||
export default async function Home() { | ||
const session = await getSession(); | ||
const email = session?.user.email || null | ||
return ( | ||
|
||
<div className="text-center py-4"> | ||
<Link href="/billing">Go to the Billing page →</Link> | ||
|
||
{session ? ( | ||
<> | ||
<p class="mb-4">Welcome, {email}</p> | ||
<Link href="/billing">Go to the Billing page →</Link> | ||
</> | ||
) : ( | ||
<Link href="/login">Sign in</Link> | ||
)} | ||
|
||
</div> | ||
|
||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use client'; | ||
|
||
import { useState } from 'react'; | ||
import { Loader2 } from 'lucide-react'; | ||
import LemonSqueezy from '@lemonsqueezy/lemonsqueezy.js' | ||
|
||
const ls = new LemonSqueezy(process.env.LEMONSQUEEZY_API_KEY); | ||
|
||
|
||
export default function UpdateBillingLink({ subscription }) { | ||
|
||
const [isMutating, setIsMutating] = useState(false) | ||
|
||
async function openUpdateModal(e) { | ||
|
||
e.preventDefault() | ||
|
||
setIsMutating(true) | ||
|
||
/* Fetch the subscription */ | ||
try { | ||
const res = await ls.getSubscription({ id: subscription.lemonSqueezyId }) | ||
// TODO: Use Lemon.js | ||
window.location = res['url']['update_payment_method'] | ||
} catch (err) { | ||
alert(err['errors'][0]['detail']) | ||
} | ||
|
||
setIsMutating(false) | ||
|
||
} | ||
|
||
return ( | ||
<a href="" className="mb-2 text-sm text-gray-500" onClick={openUpdateModal}> | ||
Update your payment method | ||
<Loader2 className={"animate-spin inline-block relative top-[-1px] ml-2 w-8" + (!isMutating ? ' invisible' : 'visible')} /> | ||
</a> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `userId` to the `Subscription` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Subscription" ADD COLUMN "userId" TEXT NOT NULL DEFAULT 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "Subscription" ALTER COLUMN "userId" DROP DEFAULT; |