Skip to content

Instantly share code, notes, and snippets.

View RomikMakavana's full-sized avatar

Romik Makavana RomikMakavana

View GitHub Profile
const persons = realm.objects('Person').filtered('name NOT IN $0', namesToSearch);
import Realm from 'realm';
const PersonSchema = {
name: 'Person',
properties: {
id: 'string',
name: 'string',
},
};
import { Platform, NativeModules } from 'react-native';
const { FileSystem } = NativeModules;
const path = `${FileSystem.documentDirectory}/myFile.txt`;
FileSystem.getInfo(path)
.then(stats => {
if (stats.exists) {
console.log('File exists');
import RNFS from 'react-native-fs';
const filePath = RNFS.DocumentDirectoryPath + '/example.txt';
RNFS.exists(filePath)
.then((exists) => {
if (exists) {
console.log('File exists');
} else {
console.log('File does not exist');
@RomikMakavana
RomikMakavana / sql-injection-secure.js
Created February 13, 2023 06:38
Prevent Sql Injection in Realm Database - React Native
import Realm from 'realm';
const PersonSchema = {
name: 'Person',
properties: {
name: 'string',
age: 'int',
},
};
import React, { useState } from 'react';
import { Button, Grid, IconButton, InputAdornment, TextField } from "@mui/material";
import { Visibility, VisibilityOff } from "@mui/icons-material";
import { useSnackbar } from 'notistack';
import { NavLink, useNavigate } from 'react-router-dom';
import AuthService from '../services/auth';
const Login = () => {
const [passwordVisibility, setPasswordVisibility] = useState(false);
const [processing, setProcessing] = useState(false);
AuthService.login = (email, password) => {
const fauth = getAuth();
return new Promise((resolve, reject) => {
signInWithEmailAndPassword(fauth, email, password).then((user) => {
if (user) {
resolve({ status: true, message: "Login successfully." });
} else {
resolve({ status: false, message: "Incorrect Email or Password." });
}
AuthService.logout = async () => {
return new Promise((resolve) => {
const fauth = getAuth();
fauth.signOut().then(() => {
resolve({ status: true, message: "Logged out successfully." });;
}).catch(err => {
resolve({ status: true, message: "Logged out successfully." });
});
})
}
import { PowerSettingsNew } from '@mui/icons-material';
import { Button, Grid } from '@mui/material';
import { useSnackbar } from 'notistack';
import React, { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import AuthService from '../services/auth';
const Welcome = () => {
const [name, setName] = useState("");
import React, { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import AuthService from '../services/auth';
const UnAuthGuard = ({ component }) => {
const [status, setStatus] = useState(false);
const navigate = useNavigate();
useEffect(() => {
checkToken();