### Create a Static Landing Page with SEO Components (JavaScript) Source: https://shipfa.st/docs/-old/tutorials/static-page This JavaScript code snippet demonstrates how to create a simple static landing page using ShipFast's components. It includes the use of `TagSEO` for meta tags and `TagSchema` for rich snippets to improve Google ranking. The example also shows how to apply a DaisyUI theme and structure basic content. ```javascript import TagSEO from "@/components/TagSEO"; import TagSchema from "@/components/TagSchema"; export default function Landing() { return ( <> {/* 👇 Add all your SEO tags for the page (title, keywords, description, open graph etc...) */} {/* 👇 Tells Google what type is your site. In this example, we could say it's a SoftwareApplication. It's used for Rich Snippets */}

Food recipes you'll love 🥦

Our AI will generate recipes based on your preferences. New recipes will be added every week!

Vegetables
); } ``` -------------------------------- ### Adding SEO Tags to Next.js Page Component Source: https://shipfa.st/docs/-old/features/seo This snippet demonstrates how to include the TagSEO component in a Next.js page to set title and canonical slug for improved search engine optimization. It requires the TagSEO component to be imported and used within the page's JSX return statement. The component applies meta tags to the head section, enhancing page visibility on search engines like Google, with no additional dependencies beyond the project's setup. ```jsx return ( <>

Tutorial

/> ) ``` -------------------------------- ### Rendering Structured Data in Next.js Components Source: https://shipfa.st/docs/features/seo This code shows how to include structured data schema tags on a page to improve Google understanding and enable rich snippets. It uses the renderSchemaTags function from /libs/seo.js within a JSX component. No specific inputs beyond the function call; outputs are embedded schema tags in the HTML head. Limitation: Schema details must be defined in the seo.js library; relevant only for pages with applicable structured data like articles or products. ```javascript import { renderSchemaTags } from "@/libs/seo"; export default function Page() { return ( <> {renderSchemaTags()}

Ship Fast

...
); } ``` -------------------------------- ### Install Rate Limiting Packages Source: https://shipfa.st/docs/security/rate-limiting-api-routes Installs the necessary Upstash Redis and Rate Limit packages for Node.js projects. These packages are essential for implementing API route protection. ```bash npm install @upstash/redis @upstash/ratelimit ``` -------------------------------- ### Create a Private User Dashboard Page with Next-Auth and MongoDB Source: https://shipfa.st/docs/tutorials/private-page This example demonstrates how to create a private user dashboard using Next.js App Router, Next-Auth for authentication, and MongoDB for user data storage. It fetches user data based on the session and displays it on the page, ensuring only authenticated users can access this information. Ensure you have configured Next-Auth and connected to MongoDB as per the project setup. ```javascript import { getServerSession } from "next-auth"; import { authOptions } from "@/libs/next-auth"; import connectMongo from "@/libs/mongoose"; import User from "@/models/User"; export default async function Dashboard() { await connectMongo(); const session = await getServerSession(authOptions); const user = await User.findById(session.user.id); return ( <>

User Dashboard

Welcome {user.name} 👋

Your email is {user.email}

); } ``` -------------------------------- ### Implement Sign-In Button with NextAuth in JavaScript Source: https://shipfa.st/docs/-old/tutorials/user-auth This JavaScript code defines a React component for a sign-in button that uses NextAuth's signIn function to initiate authentication. It requires NextAuth setup in the API and a config file defining the callbackUrl for post-login redirection to pages like /dashboard. Outputs a clickable button that triggers the sign-in process; limitations include dependency on NextAuth configuration and no handling for authentication errors in this component. ```javascript 1import { signIn } from "next-auth/react"; 2import config from "@/config"; 4const SigninButton = () => { 5 return ( 6 12 ); 13}; 15export default SigninButton; ``` -------------------------------- ### Custom SEO Metadata in Next.js Pages Source: https://shipfa.st/docs/features/seo This snippet demonstrates how to add custom SEO tags like title and canonical URL to a specific page without overriding all defaults. It relies on the getSEOTags function from /libs/seo.js, which integrates with Next.js metadata export. Inputs include title and relative canonical URL; outputs are SEO-optimized metadata for the page. Limitation: Requires updating each page individually for custom tags. ```javascript import { getSEOTags } from "@/libs/seo"; ... export const metadata = getSEOTags({ title: "Terms and Conditions | ShipFast", canonicalUrlRelative: "/tos", }); export default async function TermsAndConditions() { ... } ``` -------------------------------- ### Create Private Dashboard with Next.js Authentication Source: https://shipfa.st/docs/-old/tutorials/private-page Implements a protected dashboard component using the usePrivate hook to enforce authentication and manage session state. Displays conditional user information and provides logout functionality via NextAuth.js. Requires authentication setup and the custom usePrivate hook from the hooks folder. ```jsx import { useState } from "react"; import { signOut } from "next-auth/react"; import apiClient from "@/libs/api"; import { usePrivate } from "@/hooks/usePrivate"; import TagSEO from "@/components/TagSEO"; export default function Dashboard() { // Custom hook to make private pages easier to deal with (see /hooks folder) const [session, status] = usePrivate({}); const [isLoading, setIsLoading] = useState(false); // Show a loader when the session is loading. Not needed but recommended if you show user data like email/name if (status === "loading") { return

Loading...

; } return ( <>

Your Food Recipes

{status === "authenticated" ? `Welcome ${session?.user?.name}` : "You are not logged in"}
{session?.user?.email ? `Your email is ${session?.user?.email}` : ""}

); } ``` -------------------------------- ### Add Custom Font in Layout.js (JavaScript) Source: https://shipfa.st/docs/-old/components This example demonstrates how to integrate a custom font from Google Fonts into the ShipFast project. It involves importing the desired font from `next/font/google` and then replacing the current font variable in the `Layout.js` file. ```javascript import { Bricolage_Grotesque } from "next/font/google"; const font = Bricolage_Grotesque({ subsets: ["latin"] }); ``` -------------------------------- ### Protected User Profile Update API in Next.js Source: https://shipfa.st/docs/tutorials/api-call This functionality enables secure API calls from the client to update user data, using Next-Auth for session management and a MongoDB backend for persistence. The client-side component makes a POST request via an axios helper that handles errors and redirects, while the server-side route validates the session, connects to the database, and updates the user email. Dependencies include Next-Auth, Mongoose, and axios; inputs are user email, outputs are updated user data or error messages; limitations include requiring proper database configuration and session setup. ```javascript "use client" import { useState } from "react"; import apiClient from "@/libs/api"; const UserProfile = () => { const [isLoading, setIsLoading] = useState(false); const saveUser = async () => { setIsLoading(true); try { const { data } = await apiClient.post("/user", { email: "new@gmail.com", }); console.log(data); } catch (e) { console.error(e?.message); } finally { setIsLoading(false); } }; return ( ); }; export default UserProfile; ``` ```javascript import { NextResponse } from "next/server"; import { getServerSession } from "next-auth/next"; import { authOptions } from "@/libs/next-auth"; import connectMongo from "@/libs/mongoose"; import User from "@/models/User"; export async function POST(req) { const session = await getServerSession(authOptions); if (session) { const { id } = session.user; const body = await req.json(); if (!body.email) { return NextResponse.json({ error: "Email is required" }, { status: 400 }); } try { await connectMongo(); const user = await User.findById(id); if (!user) { return NextResponse.json({ error: "User not found" }, { status: 404 }); } user.email = body.email; await user.save(); return NextResponse.json({ data: user }, { status: 200 }); } catch (e) { console.error(e); return NextResponse.json( { error: "Something went wrong" }, { status: 500 } ); } } else { // Not Signed in return NextResponse.json({ error: "Not signed in" }, { status: 401 }); } } ``` -------------------------------- ### ButtonLead Component Integration for ShipFast (JavaScript) Source: https://shipfa.st/docs/-old/tutorials/ship-in-5-minutes This JavaScript code demonstrates how to integrate the ButtonLead component within different sections of a ShipFast landing page. It shows how to apply specific styling props like `extraStyle` for different use cases, such as the Hero/CTA sections versus the Pricing section. This component is used for main call-to-action buttons. ```javascript import ButtonLead from "@/components/ButtonLead"; ... {/* For the Hero & CTA use this 👇 */} {/* For the Pricing use this instead 👇 */}
... ``` -------------------------------- ### Index Page Structure for ShipFast Landing Page (JavaScript) Source: https://shipfa.st/docs/-old/tutorials/ship-in-5-minutes This JavaScript code defines the main structure for the homepage of a ShipFast landing page. It imports various components like Header, Hero, Pricing, FAQ, CTA, and Footer, and renders them within a main content area. This serves as the entry point for the application. ```javascript import Header from "@/components/Header"; import Hero from "@/components/Hero"; import Pricing from "@/components/Pricing"; import FAQ from "@/components/FAQ"; import CTA from "@/components/CTA"; import Footer from "@/components/Footer"; export default function Home() { return ( <>