> ## Documentation Index
> Fetch the complete documentation index at: https://docs.civic.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Node.JS

> The Civic Auth SDK also works with any Node.js backend.

The core integration points here are as follows:

* Direct users to the Civic Auth login page

* Set up an endpoint that the auth server should redirect to once complete

* Set up middleware to ensure only logged-in users can access protected parts of your app.

Use these guides to set up Civic Auth with any of the most common Node.js server libraries.

<CardGroup cols={3}>
  <Card title="Express" href="/integration/nodejs/express" img="https://mintcdn.com/civic/O4L8MDyrwt6gcvaS/images/auth/integration/express.jpeg?fit=max&auto=format&n=O4L8MDyrwt6gcvaS&q=85&s=107e1007b591deb75311611d245a5d47" width="490" height="275" data-path="images/auth/integration/express.jpeg" />

  <Card title="Hono" href="/integration/nodejs/hono" img="https://mintcdn.com/civic/O4L8MDyrwt6gcvaS/images/auth/integration/hono.jpeg?fit=max&auto=format&n=O4L8MDyrwt6gcvaS&q=85&s=b14f44701ccfc34fb45888c4c4b2e876" width="490" height="275" data-path="images/auth/integration/hono.jpeg" />

  <Card title="Fastify" href="/integration/nodejs/fastify" img="https://mintcdn.com/civic/O4L8MDyrwt6gcvaS/images/auth/integration/fastify.jpeg?fit=max&auto=format&n=O4L8MDyrwt6gcvaS&q=85&s=108ecc6d8b61b259ac0956f9fda8b49f" width="490" height="276" data-path="images/auth/integration/fastify.jpeg" />
</CardGroup>

## Usage

Civic Auth SDK is optimized for React and Next.js. However, some features are usable in other JS environments. For example, the `getUser` function verifies and parses the user information stored in the id\_token cookie and makes it available to your app.

### Getting User Information on the Backend

Here are some examples of using the getUser function in popular Node.JS server environments. Note - this snippet assumes you have followed the steps to integrate login with your app as described [here](/integration/nodejs).
You have to provide a class that tells Civic how to load and store cookies, by implementing the CookieStorage interface.
We provide examples for [Express](https://docs.civic.com/integration/nodejs/express#4-set-up-cookies), [Hono](https://docs.civic.com/integration/nodejs/hono#4-set-up-cookies) and [Fastify](https://docs.civic.com/integration/nodejs/fastify#4-set-up-cookies).

<CodeGroup>
  ```express Express theme={null}
  import { CivicAuth } from "@civic/auth/server";

  app.get('/admin/hello', async (req, res) => {
    // You need to provide a class implementing the CookieStorage interface,
    // telling Civic how to load and store cookies.
    // See the Express page for an example:
    // https://docs.civic.com/integration/nodejs/express#4-set-up-cookies

    const yourCookieStorageInstance = new ExpressCookieStorage();
    const civicAuth = new CivicAuth(yourCookieStorageInstance);
    const user = await civicAuth.getUser();
    res.send(`hello ${user.name}!`);
  });
  ```

  ```hono Hono theme={null}
  import { CivicAuth } from "@civic/auth/server";

  app.get('/admin/hello', async (c) => {
    // You need to provide a class implementing the CookieStorage interface,
    // telling Civic how to load and store cookies.
    // See the Hono page for an example:
    // https://docs.civic.com/integration/nodejs/hono#4-set-up-cookies

    const yourCookieStorageInstance = new HonoCookieStorage();
    const civicAuth = new CivicAuth(yourCookieStorageInstance);
    const user = await civicAuth.getUser();
    return c.text(`hello ${user.name}!`);
  });
  ```

  ```fastify Fastify theme={null}
   import { CivicAuth } from "@civic/auth/server";

  fastify.get('/admin/hello', async (request, reply) => {
    // You need to provide a class implementing the CookieStorage interface,
    // telling Civic how to load and store cookies.
    // See the Fastify page for an example:
    // https://docs.civic.com/integration/nodejs/fastify#4-set-up-cookies

    const yourCookieStorageInstance = new FastifyCookieStorage();
    const civicAuth = new CivicAuth(yourCookieStorageInstance);
    const user = await civicAuth.getUser();
    reply.send(`hello ${user.name}!`);
  });
  ```
</CodeGroup>

<Info>
  The `name` property is used as an example here, check out the [React Usage page](/integration/react#usage) to see the entire basic user object structure.
</Info>
