Implement API with authentication and weather integration#252
Open
roselletabuena wants to merge 1 commit intoZeff01:mainfrom
Open
Implement API with authentication and weather integration#252roselletabuena wants to merge 1 commit intoZeff01:mainfrom
roselletabuena wants to merge 1 commit intoZeff01:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backend Technical Assessment
A RESTful API backend built with TypeScript and Fastify, leveraging AWS services for authentication and serverless deployment.
Tech Stack
Project Structure
API Routes
POST
/api/auth/registerRegisters a new user via AWS Cognito.
Request Body:
{ "email": "user@example.com", "password": "YourPassword123!" }Response:
{ "message": "User registered. Check your email to confirm your account.", "userSub": "4458e488-*", "confirmed": false }POST
/api/auth/loginAuthenticates an existing user and returns JWT tokens from Cognito.
Request Body:
{ "email": "user@example.com", "password": "YourPassword123!" }Response:
{ "accessToken": "eyJ...", "idToken": "eyJ...", "refreshToken": "eyJ...", "expiresIn": "" }GET
/api/weatherReturns weather data. Protected route — requires a valid Cognito
accessTokenin the Authorization header.Headers:
Response (Success):
{ "city": "Manila", "country": "PH", "timezone": "Asia/Manila", "temperature": { "current": 26.6, "feels_like": 29.7, "unit": "°C" }, "humidity": "70%", "precipitation": "0 mm", "wind": { "speed": "8 km/h", "direction": "8°" }, "visibility": "24140 m", "weather_code": 1, "timestamp": "2026-02-18T23:00" }Response (Unauthorized):
{ "error": "Invalid or expired token" }Request Validation
Auth routes include JSON Schema validation powered by Fastify's built-in validation support. Requests that fail validation are rejected before reaching the handler, returning a
400 Bad Requestwith a descriptive error message.POST /api/auth/registerenforces:email— required, must be a valid email formatpassword— required, minimum 8 charactersPOST /api/auth/loginenforces:email— required, must be a valid email formatpassword— requiredValidation – Missing Email Property
Validation – Wrong Email Format
Screenshots
Register
Login
Weather – Success
Weather – Failed (Unauthorized)
Setup & Installation
Clone the repository and install dependencies:
Configure environment variables by creating a
.envfile:Run in development:
AWS Configuration
Ensure your IAM role has the appropriate permissions for Cognito (
cognito-idp:*) and any other AWS services used.