Skip to content

Commit

Permalink
feat:annoying bug caused by react-native-dotenv fixed, it rewrites ex…
Browse files Browse the repository at this point in the history
…po-router config so screen doesn't load
  • Loading branch information
DeveloperMindset123 committed Sep 27, 2024
1 parent 752841b commit bc05018
Show file tree
Hide file tree
Showing 19 changed files with 437 additions and 800 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
rules: {
'@typescript-eslint/no-explicit-any': 'off',
},
env: {
node: true, // This line tells ESLint to expect Node.js global variables and scoping.
},
Expand Down
19 changes: 0 additions & 19 deletions app.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,6 @@ module.exports = {
typedRoutes: true,
tsconfigPaths: true,
},
plugins: [
'expo-font',
{
// miscellaneous
fonts: [
'src/assets/fonts/pacifico.ttf',
'src/assets/fonts/playpenBold.ttf',
'src/assets/fonts/playpenExtraBold.ttf',
'src/assets/fonts/playpenLight.ttf',
'src/assets/fonts/playpenMedium.ttf',
'src/assets/fonts/playpenRegular.ttf',
'src/assets/fonts/playpenSemiBold.ttf',
'src/assets/fonts/playpenThin.ttf',
'src/assets/fonts/playpenVariable.ttf',
'src/assets/fonts/sofadi.ttf',
'src/assets/fonts/spaceMono.ttf',
],
},
],
slug: 'expo-router-starter-kit',
version: '1.0.0',
orientation: 'portrait',
Expand Down
1 change: 0 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module.exports = function (api) {
plugins: [
'@babel/plugin-proposal-export-namespace-from',
'react-native-reanimated/plugin',
['module:react-native-dotenv'],
],
};
};
34 changes: 19 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,35 @@
"build and view log": "eas build:list"
},
"dependencies": {
"@expo/cli": "^0.10.11",
"@expo/vector-icons": "^14.0.2",
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
"@expo/cli": "^0.18.29",
"@expo/config-plugins": "~8.0.0",
"@expo/metro-config": "~0.18.11",
"@expo/prebuild-config": "~7.0.0",
"@expo/vector-icons": "14.0.3",
"@hookform/resolvers": "^3.2.0",
"@prisma/client": "5.20.0",
"@react-native-async-storage/async-storage": "1.23.1",
"@react-native-async-storage/async-storage": "2.0.0",
"@react-native-picker/picker": "2.7.5",
"@react-navigation/material-top-tabs": "^6.6.3",
"@react-navigation/native": "^6.1.7",
"@rneui/themed": "^4.0.0-rc.8",
"@shopify/flash-list": "^1.6.4",
"@types/react-native": "^0.72.2",
"@shopify/flash-list": "1.6.4",
"@types/bcrypt": "^5.0.2",
"@types/jsonwebtoken": "^9.0.7",
"bcrypt": "^5.1.1",
"bcrypt-ts": "^5.0.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"expo": "51.0.28",
"expo": "51.0.34",
"expo-device": "~6.0.2",
"expo-font": "~12.0.10",
"expo-image": "~1.12.13",
"expo-image": "1.13.0",
"expo-linking": "^6.3.1",
"expo-router": "3.5.23",
"expo-splash-screen": "~0.27.5",
"expo-splash-screen": "0.27.6",
"expo-status-bar": "~1.12.1",
"expo-updates": "~0.25.22",
"expo-updates": "0.25.25",
"expo-web-browser": "~13.0.3",
"jsonwebtoken": "^9.0.2",
"lucide-react-native": "^0.359.0",
Expand All @@ -46,12 +52,12 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.74.5",
"react-native-gesture-handler": "^2.16.1",
"react-native-gesture-handler": "2.16.1",
"react-native-pager-view": "6.3.0",
"react-native-reanimated": "3.10.1",
"react-native-safe-area-context": "4.10.5",
"react-native-screens": "^3.31.1",
"react-native-svg": "^15.2.0",
"react-native-screens": "3.31.1",
"react-native-svg": "15.2.0",
"react-native-tab-view": "^3.5.2",
"react-native-url-polyfill": "^2.0.0",
"tailwind-merge": "^2.4.0",
Expand All @@ -60,17 +66,15 @@
},
"devDependencies": {
"@babel/core": "^7.24.7",
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
"@types/react": "~18.2.79",
"@types/react-native": "^0.72.2",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"eslint": "^8.55.0",
"eslint-plugin-react-hooks": "^4.6.0",
"prisma": "^5.20.0",
"react-native-dotenv": "^3.4.11",
"tailwindcss": "3.3.2",
"typescript": "^5.3.3"
"typescript": "5.3.3"
},
"resolutions": {
"react-refresh": "~0.14.0"
Expand Down
2 changes: 0 additions & 2 deletions src/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { ThemeToggle } from '@/components/core/toggle';
import { ThemeProvider } from '@react-navigation/native';
import { useFonts } from 'expo-font';

// TODO : fonts not loading
// @see https://stackoverflow.com/questions/68569844/react-native-expo-custom-fonts-not-loading-with-font-loadasync
/**
* https://www.npmjs.com/package/react-native-keyboard-controller
Expand Down Expand Up @@ -102,7 +101,6 @@ function RootLayoutNav() {
},
}}
>
{/**TODO : Remove later the test page */}
<Stack.Screen
name="index"
options={{ title: 'Welcome', headerShown: true, headerBackVisible: false }}
Expand Down
1 change: 1 addition & 0 deletions src/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const Landing: React.FC = () => {
}
}
}, [width, height]);
// eslint-disable-next-line @typescript-eslint/no-var-requires
const imagePath = require('src/assets/images/Landing-Screen-Image-Updated.png');

return (
Expand Down
11 changes: 6 additions & 5 deletions src/app/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import React from 'react';
import { Text, KeyboardAvoidingView, ScrollView, Platform } from 'react-native';
import { SignupIcon } from '@/lib/utils/getSvgs';
import getWindowDimensions from '@/lib/utils/getWindowDimension';
import { SignupButton } from '@/components/core/signupButton';
//import { SignupButton } from '@/components/core/signupButton';
import { TextInputComponent } from '@/components/core/textInputComponent';
import { getSignupStyles } from '@/components/core/textInputComponent/getSignupStyles';

// @see https://dev.to/mihaiandrei97/jwt-authentication-using-prisma-and-express-37nk --> for implementing authentication.
const register: React.FC = () => {
const [passwordMatch, setPasswordMatch] = React.useState<boolean>(false);
//const [passwordMatch, setPasswordMatch] = React.useState<boolean>(false);
const { width, height } = getWindowDimensions();
const { titleFontStyling, secondaryTextStyling } = getSignupStyles();
let inputBoxWidth = width * 0.9;
let inputBoxHeight = height * 0.07;
//let inputBoxWidth = width * 0.9;
//let inputBoxHeight = height * 0.07;
// @see https://www.npmjs.com/package/react-native-dotenv
const public_key = process.env.EXPO_PUBLIC_KEY;
//const public_key = process.env.EXPO_PUBLIC_KEY;
//console.log(process.env.EXPO_PUBLIC_KEY);

return (
Expand Down
Empty file added src/lib/api/auth/auth.routes.ts
Empty file.
61 changes: 61 additions & 0 deletions src/lib/api/auth/auth.services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import db from '@/lib/utils/db';
import hashToken from '@/lib/utils/hashToken';

// TODO : too many errors being raised with using any
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function addRefreshTokenToWhiteList({
jti,
refreshToken,
userId,
}: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
jti: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
refreshToken: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
userId: any;
}) {
return db.refreshTokens.create({
data: {
id: jti,
hashedToken: hashToken(refreshToken),
userId,
},
});
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function findRefreshTokenById(id: any) {
return db.refreshTokens.findUnique({
where: {
id,
},
});
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function deleteRefreshToken(id: any) {
return db.refreshTokens.updateMany({
where: {
id,
},
data: {
revoked: true,
},
});
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function revokeTokens(userId: any) {
return db.refreshTokens.updateMany({
where: {
userId,
},
data: {
revoked: true,
},
});
}

// TODO : Continue at STEP 7
Empty file.
29 changes: 29 additions & 0 deletions src/lib/api/users/users.services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { hashSync } from 'bcrypt-ts';
import db from '@/lib/utils/db';

// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
function findUserByEmail(email: any) {
return db.user.findUnique({
where: {
email,
},
});
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function createUserByEmailAndPassword(user: any) {
// TODO : Modify this as needed
user.password = hashSync(user.password, 12);
return db.user.create({
data: user,
});
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function findUserById(id: any) {
return db.user.findUnique({
where: {
id,
},
});
}
32 changes: 0 additions & 32 deletions src/lib/database/supabase.ts

This file was deleted.

12 changes: 2 additions & 10 deletions src/lib/env-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,8 @@ const schema = z.object({
EXPO_PUBLIC_API_URL: z.string().url(),
EXPO_PUBLIC_REQRES_API_URL: z.string().url(),
SEGMENT_KEY: z.string().url().optional(),
// TODO : Cleanup later
/*
EXPO_PUBLIC_KEY: z.string().url(),
EXPO_PUBLIC_SECRET_KEY: z.string().url().optional(),
EXPO_PUBLIC_PROJECT_URL: z.string().url().optional(),
EXPO_PUBLIC_JWT_SECRET: z.string().url().optional(),
EXPO_PUBLIC_SUPABASE_DATABASE_PASSWORD: z.string().url().optional(),
EXPO_PUBLIC_HCAPTCHA_SITE_KEY: z.string().url().optional(),
EXPO_PUBLIC_HCAPTCHA_SECRET: z.string().url().optional(),
EXPO_PUBLIC_RESEND_API_KEY: z.string().url().optional(), */
JWT_ACCESS_SECRET: z.string().url().optional(),
JWT_REFRESH_SECRET: z.string().url().optional(),
});

const parsed = schema.safeParse(process.env);
Expand Down
3 changes: 3 additions & 0 deletions src/lib/utils/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { PrismaClient } from '@prisma/client';
const db = new PrismaClient();
export default db;
1 change: 1 addition & 0 deletions src/lib/utils/getWindowDimension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useWindowDimensions } from 'react-native';

const getWindowDimensions = () => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const { width, height, scale, fontScale } = useWindowDimensions();
return {
width,
Expand Down
6 changes: 6 additions & 0 deletions src/lib/utils/hashToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import crypto from 'crypto';

export default function hashToken(token: crypto.BinaryLike) {
// TODO : hashing logic, modify as needed
return crypto.createHash('sha512').update(token).digest('hex');
}
51 changes: 51 additions & 0 deletions src/lib/utils/jwt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
// ? for encryption
import * as jwt from 'jsonwebtoken';

// TODO : Remove later
// see if it exists
console.log(process.env.JWT_ACCESS_SECRET);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function generateAccessToken(user: any) {
// ** @see https://jwt.io/introduction
return jwt.sign(
{
userId: user?.id,
},
// TODO : Remove string before commiting
process.env.JWT_ACCESS_SECRET ? process.env.JWT_ACCESS_SECRET : 'MYSECRET321',
{
expiresIn: '5m',
}
);
}

// TODO : Remove this once the function is invoked with the appropriate params
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function generateRefreshToken(user: { id: any }, jti: any) {
return jwt.sign(
{
userId: user.id,
jti,
},
process.env.JWT_REFRESH_SECRET ? process.env.JWT_REFRESH_SECRET : 'MYOTHERSECRET321',
{
// TODO : Modify this as needed
expiresIn: '8h',
}
);
}

// TODO : Remove this once the functon is invoked with the appropriate params
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function generateAccessAndRefreshTokens(user: any, jti: any) {
const accessToken = generateAccessToken(user);
const refreshToken = generateRefreshToken(user, jti);

console.log(`The access token is ${accessToken}\n`);
console.log(`The refresh token is ${refreshToken}`);
return {
accessToken,
refreshToken,
};
}
Loading

0 comments on commit bc05018

Please sign in to comment.