darenc9 / FitFuture

https://fit-future.vercel.app
0 stars 0 forks source link

Devon/deploy #81

Closed darenc9 closed 2 months ago

darenc9 commented 2 months ago

Backend-api

Frontend-ui

Authentication Features

Exercises

Authentication Usage

Protecting a route

Example before:

Your page might look something like this:

"use client";
import React from 'react';

export default Home() {
    return (
        <main>Example</main>
    );
}

Example after:

Import and use withAuthenticator to protect route: using export default withAuthenticator(PageName) Import and use useAuthenticator to pull user object Include "use client"; After Next.js 13.4+: to use Server Components inside the app directory, we wrap everything inside a Client Component. Adding use client; enables this for us

"use client";
import React from 'react';
import { withAuthenticator } from "@aws-amplify/ui-react";
import { useAuthenticator } from '@aws-amplify/ui-react';

function Home() {
  const { user, signOut } = useAuthenticator((context) => [context.user]);
  return (
    <main>
    <h1>Hello {user.username}</h1>
    <button onClick={signOut} > Sign out </button>
  </main>
  );
}
export default withAuthenticator(Home);
vercel[bot] commented 2 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fit-future ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 18, 2024 7:56pm
fit-future-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 18, 2024 7:56pm