Skip to content

Commit

Permalink
Refactor authentication URLs to use APP_URL constant and add example.…
Browse files Browse the repository at this point in the history
…env file for environment variables
  • Loading branch information
upayanmazumder committed Dec 12, 2024
1 parent 0de169c commit 5cb3d35
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 15 deletions.
5 changes: 3 additions & 2 deletions CLI/src/commands/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import sys
import time
from ..constants import APP_URL

# Flask and Console initialization
app = Flask(__name__)
Expand All @@ -29,7 +30,7 @@ def handle_auth_response():
# Exit the server after completing the task
shutdown_flag_file = "shutdown_flag.tmp"
open(shutdown_flag_file, "w").close() # Create a flag file to signal shutdown
return redirect("https://cas.upayan.dev/auth/connect/success")
return redirect(f"{APP_URL}/auth/connect/success")

@auth_bp.route("/favicon.ico")
def favicon():
Expand All @@ -40,7 +41,7 @@ def run_server():
app.run(port=8000, use_reloader=False) # Disable reloader to prevent duplicate shutdown signals

def auth_command():
url = "https://cas.upayan.dev/auth/connect?redirect_uri=http://localhost:8000"
url = f"{APP_URL}/auth/connect?redirect_uri=http://localhost:8000"
webbrowser.open(url)
console.print("[bold green]Starting server on [link=http://localhost:8000]http://localhost:8000[/link]")

Expand Down
5 changes: 4 additions & 1 deletion CLI/src/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import os

API_URL = "https://api.cas.upayan.dev"
APP_URL = "https://cas.upayan.dev"

if os.getenv("ENV") == "development":
API_URL = "http://localhost:4000"
API_URL = "http://localhost:4000"
APP_URL = "http://localhost:3000"
3 changes: 1 addition & 2 deletions app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

# env files (can opt-in for committing if needed)
.env*
.env

# vercel
.vercel
Expand Down
9 changes: 9 additions & 0 deletions app/example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
NEXT_PUBLIC_FIREBASE_API_KEY=
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=
NEXT_PUBLIC_FIREBASE_PROJECT_ID=
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=
NEXT_PUBLIC_FIREBASE_APP_ID=
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=

NEXT_PUBLIC_ENV= #leave blank for production. for development, use development
3 changes: 3 additions & 0 deletions app/shared/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const ENV = process.env.NEXT_PUBLIC_ENV;

export const NEXT_PUBLIC_API_URL = ENV === 'development' ? 'http://localhost:4000' : 'https://api.cas.upayan.dev';
5 changes: 3 additions & 2 deletions app/src/components/auth/signup/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import React, { useState } from 'react';
import { createUserWithEmailAndPassword } from 'firebase/auth';
import { auth } from '../../../../shared/firebase';
import styles from '../auth.module.css';
import { useRouter } from 'next/navigation'; // Import the router to handle the redirection
import { useRouter } from 'next/navigation';
import { NEXT_PUBLIC_API_URL } from '../../../../shared/api';

const Signup = () => {
const [email, setEmail] = useState('');
Expand All @@ -20,7 +21,7 @@ const Signup = () => {

try {
// Step 1: Send request to the API to sign up
const response = await fetch('https://api.cas.upayan.dev/auth/signup', {
const response = await fetch(`${NEXT_PUBLIC_API_URL}/auth/signup`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
8 changes: 0 additions & 8 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,4 @@ FIREBASE_TOKEN_URI=
FIREBASE_AUTH_PROVIDER_CERT_URL=
FIREBASE_CLIENT_CERT_URL=

FIREBASE_API_KEY=
FIREBASE_AUTH_DOMAIN=
FIREBASE_PROJECT_ID=
FIREBASE_STORAGE_BUCKET=
FIREBASE_MESSAGING_SENDER_ID=
FIREBASE_APP_ID=
FIREBASE_MEASUREMENT_ID=

ENV= #leave blank for production. for development, use development

0 comments on commit 5cb3d35

Please sign in to comment.