Skip to content

vamshi1188/Authify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

🔐 JWT Authentication App

A secure, full-stack authentication system built with Go & JavaScript

Go JavaScript SQLite Bootstrap

License Version Status


📖 Overview

A modern authentication system featuring JWT tokens, secure cookie sessions, and real-time validation. Built with Go Fiber backend and Vanilla JavaScript frontend for maximum performance and simplicity.


🏗️ Project Architecture

🛠️ Backend (Go + Fiber)

  • 🚀 High-performance RESTful API
  • 🔑 JWT token-based authentication
  • 🍪 Secure HttpOnly cookie sessions
  • 🗄️ SQLite database with GORM
  • 🛡️ bcrypt password hashing

🎨 Frontend (Vanilla JS)

  • Single Page Application (SPA)
  • 🧭 Client-side routing
  • Dynamic UI rendering
  • 📱 Responsive Bootstrap design
  • Real-time form validation

🚀 Quick Start

Prerequisites

  • Go 1.19+ installed
  • Node.js 16+ installed

🔧 Backend Setup

# Navigate to backend directory
cd backend

# Install dependencies
go mod tidy

# Run the server
go run main.go

🎯 Backend runs on: http://localhost:8000

🌐 Frontend Setup

# Navigate to frontend directory
cd frontend

# Start the file server
node server.js

🎯 Frontend available at: http://localhost:3000


🔌 API Reference

Method Endpoint Description Auth Required
POST /api/register 📝 Register new user
POST /api/login 🔐 User login
GET /api/user 👤 Get user profile
POST /api/logout 🚪 User logout

✨ Key Features

Feature Description
🔐 Secure Authentication JWT tokens with HttpOnly cookies
🛡️ Password Security bcrypt hashing with salt rounds
🔒 Protected Routes Authentication middleware
📱 Responsive Design Mobile-first Bootstrap UI
Real-time Validation Instant form feedback
🔄 Smart Redirects Context-aware navigation
🍪 Secure Sessions XSS-protected cookie storage
Token Expiry 24-hour automatic timeout

🔒 Security Features

🔐 Password Hashing
bcrypt with configurable salt rounds
🍪 HttpOnly Cookies
XSS protection for JWT storage
🌐 CORS Configuration
Restricted to frontend origin only
Token Expiration
Automatic 24-hour timeout

🛠️ Technology Stack

Backend Dependencies

// Core Framework
github.com/gofiber/fiber/v2

// Database ORM
gorm.io/gorm
gorm.io/driver/sqlite

// JWT Handling
github.com/golang-jwt/jwt/v4

// Password Hashing
golang.org/x/crypto/bcrypt

Frontend Dependencies

  • 🎨 Bootstrap 5 - Modern UI framework
  • Vanilla JavaScript - No framework overhead
  • 🌐 Fetch API - Native HTTP requests

📁 Project Structure

JWTAUTHAPI/
├── 📂 backend/
│   ├── 📄 main.go           # Server entry point
│   ├── 📄 models.go         # Database models
│   ├── 📄 handlers.go       # Route handlers
│   ├── 📄 middleware.go     # Auth middleware
│   └── 📄 go.mod           # Go dependencies
├── 📂 frontend/
│   ├── 📄 index.html       # Main HTML file
│   ├── 📄 script.js        # JavaScript logic
│   ├── 📄 style.css        # Custom styles
│   └── 📄 server.js        # Static file server
└── 📄 README.md

🎯 Usage Examples

User Registration

const response = await fetch('/api/register', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    name: 'John Doe',
    email: '[email protected]',
    password: 'securePassword123'
  })
});

Protected Route Access

const userInfo = await fetch('/api/user', {
  credentials: 'include' // Include cookies
});

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


🌟 Star this repo if you found it helpful! 🌟

🐛 Report Bug✨ Request Feature

About

Authify is a Full Stack JWT Authentication with Go and JavaScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published