Skip to content

Commit

Permalink
Refactor to use new auth service
Browse files Browse the repository at this point in the history
  • Loading branch information
iaincollins committed Oct 26, 2024
1 parent 43df6d7 commit f7eccf5
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ name: Deploy Ardent Website to Production
# * DEPLOY_DIR should be an absolute path.
# * SERVICE_NAME should match the name of the repository in GitHub.
#
# This deployment script differs slightly from the other ardent deployment
# scripts. Updating the service in place would cause Next.js runtime errors
# during the build step. To avoid that, instead of simply updating the project
# and restarting it, it creates a copy of the current deployment, updates that
# copy and then swaps directories and restarts the service.
#
# SETUP
#
# This script assumes that Node.js is installed, that "pm2" is installed
Expand Down
8 changes: 4 additions & 4 deletions lib/auth.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { API_BASE_URL } from 'lib/consts'
import { AUTH_BASE_URL } from 'lib/consts'

async function getAccessToken () {
const res = await fetch(`${API_BASE_URL}/auth/token`, { credentials: 'include' })
const res = await fetch(`${AUTH_BASE_URL}/token`, { credentials: 'include' })
if (res.ok) {
const json = await res.json()
if (json?.accessToken) return json
Expand All @@ -10,7 +10,7 @@ async function getAccessToken () {
}

async function getCsrfToken () {
const res = await fetch(`${API_BASE_URL}/auth/csrftoken`, { credentials: 'include' })
const res = await fetch(`${AUTH_BASE_URL}/csrftoken`, { credentials: 'include' })
if (res.ok) {
const json = await res.json()
if (json.csrfToken) return json.csrfToken
Expand All @@ -25,5 +25,5 @@ async function isSignedIn () {
module.exports = {
getAccessToken,
getCsrfToken,
isSignedIn
isSignedIn,
}
4 changes: 2 additions & 2 deletions lib/cmdr.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { API_BASE_URL } from 'lib/consts'
import { AUTH_BASE_URL } from 'lib/consts'

async function getCmdrInfo (info) {
const res = await fetch(`${API_BASE_URL}/auth/cmdr/${info}`, { credentials: 'include' })
const res = await fetch(`${AUTH_BASE_URL}/cmdr/${info}`, { credentials: 'include' })
if (res.ok) return await res.json()
return null
}
Expand Down
7 changes: 7 additions & 0 deletions lib/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import getConfig from 'next/config'
// publicRuntimeConfig provides isomorphic access to specified env vars
const { publicRuntimeConfig } = getConfig()
const API_BASE_URL = publicRuntimeConfig?.API_BASE_URL ?? 'https://api.ardent-industry.com'
const AUTH_BASE_URL = publicRuntimeConfig?.AUTH_BASE_URL ?? 'https://auth.ardent-industry.com'

const SOL_COORDINATES = [0, 0, 0]
const COLONIA_COORDINATES = [-9530.5, -910.28125, 19808.125]
Expand All @@ -15,8 +16,14 @@ const COMMODITY_FILTER_DISTANCE_DEFAULT = 'Any distance'
const COMMODITY_FILTER_DISTANCE_WITH_LOCATION_DEFAULT = 100
const NO_DEMAND_TEXT = '-'

const SIGN_IN_URL = `${AUTH_BASE_URL}/signin`
const SIGN_OUT_URL = `${AUTH_BASE_URL}/signout`

module.exports = {
API_BASE_URL,
AUTH_BASE_URL,
SIGN_IN_URL,
SIGN_OUT_URL,
SOL_COORDINATES,
COLONIA_COORDINATES,
COMMODITY_FILTER_MAX_DAYS_AGO_DEFAULT,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ardent-www",
"version": "0.87.0",
"version": "0.88.0",
"description": "Ardent Industry",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions pages/cmdr.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { NavigationContext } from 'lib/context'
import { getCmdrInfo } from 'lib/cmdr'
import hexToAscii from 'lib/utils/hex-to-ascii'
import Layout from 'components/layout'
import { API_BASE_URL } from 'lib/consts'
import { SIGN_IN_URL, SIGN_OUT_URL, } from 'lib/consts'

export default () => {
const [signedIn, setSignedIn] = useState()
Expand Down Expand Up @@ -44,7 +44,7 @@ export default () => {
</p>}
{cmdrFleetCarrier?.name && cmdrFleetCarrier?.currentStarSystem && <p>Your Fleet Carrier {hexToAscii(cmdrFleetCarrier.name?.vanityName)} ({cmdrFleetCarrier.name?.callsign}) is currently located in <Link href={`/system/${cmdrFleetCarrier.currentStarSystem}`}>{cmdrFleetCarrier.currentStarSystem}</Link>.</p>}
{csrfToken &&
<form method='POST' action={`${API_BASE_URL}/auth/signout`}>
<form method='POST' action={SIGN_OUT_URL}>
<input type='hidden' name='csrfToken' value={csrfToken} />
<button className='button'>Sign out</button>
</form>}
Expand All @@ -55,7 +55,7 @@ export default () => {
<div style={{marginBottom: '0rem'}} className='heading--with-underline'><h2>Signed out</h2></div>
<div style={{padding: '0 1rem'}}>
<p>You are not signed in.</p>
<form method='GET' action={`${API_BASE_URL}/auth/signin`}>
<form method='GET' action={SIGN_IN_URL}>
<button className='button'>Sign in</button>
</form>
</div>
Expand Down

0 comments on commit f7eccf5

Please sign in to comment.