The Ansopedia User Service is a backend service responsible for managing user accounts and authentication within the Ansopedia learning platform. It provides functionalities like:
- User Registration and Login: Enables users to create new accounts and securely log in to the platform.
- User Management: Offers APIs to manage user profiles, preferences, and potentially user roles (if permission levels exist).
- Authentication: Implements robust authentication mechanisms (e.g., JWT tokens) to secure access to Ansopedia features and resources.
- Integration: Collaborates with other services like Ansopedia Studio API to manage user permissions for content creation and interaction.
Before we dive into the setup steps, let's break down the scripts in your package.json
file:
- build: Transpiles TypeScript code to JavaScript.
- dev: Starts the development server with nodemon for hot reloading.
- lint: Lints the codebase using ESLint.
- lint:fix: Automatically fixes lint errors.
- prepare: Runs husky pre-commit hooks.
- pretest: Builds the project before running tests.
- prettier:check: Checks code formatting.
- prettier:fix: Fixes code formatting automatically.
- prod: Sets the NODE_ENV to production, builds the project, and starts the server.
- start: Starts the development server using ts-node.
- test: Runs the test suite.
Follow these steps to set up the project:
-
Clone the repository:
git clone https://github.com/ansopedia/user-service.git cd user-service
-
Set up environment variables:
cp .env.example .env
-
Install dependencies:
pnpm install
-
Generate RSA Keys:
pnpm generate-keys
This script generates RSA keys and saves them to the
keys
directory. -
Add RSA Keys to Environment:
- Open your
.env
file - Copy the contents of
private.pem
to thePRIVATE_KEY
variable - Copy the contents of
public.pem
to thePUBLIC_KEY
variable - Make sure to maintain the PEM format, including the BEGIN and END lines
Example format in
.env
:PRIVATE_KEY="-----BEGIN PRIVATE KEY----- MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSj... -----END PRIVATE KEY-----" PUBLIC_KEY="-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgK... -----END PUBLIC KEY-----"
- Open your
-
Verify Setup:
pnpm test
All test cases should pass if the setup is correct.
-
Start Development Server:
pnpm dev
-
Development:
pnpm dev
: Start development server with hot reloadpnpm start
: Start server using ts-node
-
Production:
pnpm build
: Build the projectpnpm prod
: Run in production mode
-
Testing:
pnpm test
: Run test suite
-
Code Quality:
pnpm lint
: Check code stylepnpm lint:fix
: Fix code style issuespnpm prettier:check
: Check formattingpnpm prettier:fix
: Fix formatting issues
- Never commit your RSA keys to version control
- In production, use a secure key management service
- Rotate keys periodically following security best practices
- Keep your private key secure and restrict access
We welcome contributions! Please read our CONTRIBUTING.md for details.
Please read our CODE_OF_CONDUCT.md for community guidelines.
This project is licensed under the terms specified in LICENSE.