-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#19) user story view current locationas a driver i want to see m…
…y current location on a map in real time so that i can track my position and navigate the area effectively 1 backend (#27) * feat(#19): view current location as a driver i want to see my current location on a map in real time so that i can track my position and navigate the area effectively - refactor docker (separate mqtt listener and api cause they don't need to be together) - moved docker to root directory - using docker base to reuse common code - basic nearby drivers util * feat(#19): view current location as a driver i want to see my current location on a map in real time so that i can track my position and navigate the area effectively - adding JWT auth token support (refresh token, auth token) * feat(#19): view current location as a driver i want to see my current location on a map in real time so that i can track my position and navigate the area effectively - modifying map screen ui - using auth token as channel name when publishing location - changes in store - test screen (token display)
- Loading branch information
1 parent
27618ae
commit 1046728
Showing
56 changed files
with
4,698 additions
and
426 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules | ||
**/node_modules | ||
.yarn | ||
.yarnrc.yml | ||
dist | ||
.git |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,4 @@ Thumbs.db | |
|
||
.nx/cache | ||
.nx/workspace-data | ||
apps/api/logs/app.log |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"trailingComma": "none", | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"semi": true, | ||
"singleQuote": true, | ||
"endOfLine": "lf", | ||
"printWidth": 80, | ||
"proseWrap": "never", | ||
"trimTrailingWhitespace": true | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# syntax = edrevo/dockerfile-plus | ||
|
||
INCLUDE+ Dockerfile.base | ||
|
||
EXPOSE 3000 | ||
|
||
WORKDIR /app/apps/api | ||
|
||
CMD ["yarn", "dev"] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM node:18-alpine | ||
|
||
RUN apk add --no-cache git | ||
|
||
WORKDIR /app | ||
|
||
COPY package.json yarn.lock ./ | ||
|
||
COPY . . | ||
|
||
WORKDIR /app/apps/api | ||
|
||
RUN yarn install --frozen-lockfile | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# syntax = edrevo/dockerfile-plus | ||
|
||
INCLUDE+ Dockerfile.base | ||
|
||
EXPOSE 1883 | ||
|
||
WORKDIR /app/apps/api | ||
|
||
CMD ["yarn", "start-mqtt"] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Context } from 'koa'; | ||
import Driver from '../models/driver'; | ||
import { generateAccessToken } from '../utils/token-utils'; | ||
|
||
export const refreshAccessToken = async (ctx: Context) => { | ||
const { refreshToken } = ctx.request.body as any; | ||
if (!refreshToken) { | ||
ctx.status = 400; | ||
ctx.body = { error: 'Refresh token is required.' }; | ||
return; | ||
} | ||
|
||
const driver = await Driver.findOne({ where: { refreshToken } }); | ||
if (!driver) { | ||
ctx.status = 403; | ||
ctx.body = { error: 'Invalid refresh token.' }; | ||
return; | ||
} | ||
|
||
const accessToken = generateAccessToken(driver.dataValues.id); | ||
ctx.status = 200; | ||
ctx.body = { accessToken }; | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import jwt from 'jsonwebtoken'; | ||
import { Context, Next } from 'koa'; | ||
import Driver from '../models/driver'; | ||
|
||
const ACCESS_TOKEN_SECRET = process.env.ACCESS_TOKEN_SECRET || 'access-secret'; | ||
|
||
export const authenticateToken = async (ctx: Context, next: Next) => { | ||
const token = ctx.headers['authorization']?.split(' ')[1]; | ||
if (!token) { | ||
ctx.status = 401; | ||
ctx.body = { error: 'Access token required.' }; | ||
return; | ||
} | ||
|
||
try { | ||
const decoded = jwt.verify(token, ACCESS_TOKEN_SECRET) as { driverId: number }; | ||
const driver = await Driver.findByPk(decoded.driverId); | ||
if (!driver) { | ||
ctx.status = 403; | ||
ctx.body = { error: 'Invalid access token.' }; | ||
return; | ||
} | ||
ctx.state.driver = driver; | ||
await next(); | ||
} catch (error) { | ||
ctx.status = 403; | ||
ctx.body = { error: 'Invalid or expired access token.' }; | ||
} | ||
}; |
Oops, something went wrong.