https://github.com/snpranav/pangea-authn-mongodb
Demo app with Pangea AuthN and MongoDB
https://github.com/snpranav/pangea-authn-mongodb
Last synced: about 1 month ago
JSON representation
Demo app with Pangea AuthN and MongoDB
- Host: GitHub
- URL: https://github.com/snpranav/pangea-authn-mongodb
- Owner: snpranav
- License: mit
- Created: 2024-04-25T16:52:15.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-08T01:45:14.000Z (about 1 year ago)
- Last Synced: 2025-02-14T04:53:30.968Z (3 months ago)
- Language: TypeScript
- Size: 77.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pangea AuthN with Mongo Example
(Page Router Mode)## Getting Started
Copy the `.env.example` file to `.env.local` and copy your the environment variables from the Pangea AuthN console into your file.## How AuthN is setup
1. Look at the [`_app_.tsx`](./src/pages/_app.tsx) and notice the `` wrapper which retains Pangea Auth context across the app.
2. Look at the [`index.tsx`](./src/pages/index.tsx) and [`authenticated.tsx`](./src/pages/authenticated.tsx) and notice how the `useAuth` hook allows you to enable conditional routing based on user authentication status.
3. To perform serverside authentication, look at [`utils/authCheck.js`](./src/utils/authCheck.js) which defines a `withAPIAuthentication` middleware that automatically checks if a user is logged in before hitting the API logic.
4. Finally look at the `getUserInfo` function that is imported from the [`utils/authCheck.js`](./src/utils/authCheck.js) in the [`send-data.ts`](./src/pages/api/send-data.ts) API, which allows you to pull user info from the server side.