Skip to content

Instantly share code, notes, and snippets.

View gabrielEloy's full-sized avatar

Gabriel Eloy gabrielEloy

  • Quest Mindshare
  • Curitiba, Brazil
View GitHub Profile
@gabrielEloy
gabrielEloy / parse.js
Created June 23, 2021 00:18
services/parse.js
View parse.js
//at services/parse.js
import Parse from 'parse';
//checking if env is browser
if (typeof window !== "undefined") {
Parse.initialize("APP_ID","JS_KEY");
Parse.serverURL = 'https://parseapi.back4app.com/';
}
View parse.js
import Parse from 'parse';
if (typeof window !== "undefined") {
Parse.initialize(process.env.PARSE_APP_ID,process.env.PARSE_JS_KEY);
Parse.serverURL = 'https://parseapi.back4app.com/';
}
export default Parse;
View index.js
import { useState } from "react";
import styles from "../styles/Home.module.css";
import Parse from "../service/parse";
export default function Home() {
const [employeeName, setEmployeeName] = useState("");
const [employeeEmail, setEmployeeEmail] = useState("");
const [employeePassword, setEmployeePassword] = useState("");
const [employees, setEmployees] = useState([]);
View parseUserExample.js
const employee = new Parse.Object('Employee');
employee
.save({
username: employeeName,
email: employeeEmail,
password: employeePassword,
})
View getUsersFunctionExample.js
const getEmployees = async () => {
const query = new Parse.Query("Employee");
const res = await query.findAll();
const employees = res.map((employee) => ({ name: employee.get("username") }));
setEmployees(employees);
};
View _app.js
import "../styles/globals.css";
import { initializeParse } from "@parse/react-ssr";
initializeParse(
"https://parsechatarticletest.b4a.io/",
"PARSE_APP_ID", //Insert your parse app id here
"PARSE_JS_KEY", //Insert your parse JS key
);
function MyApp({ Component, pageProps }) {
View pages_index.js
import { useState } from "react";
import styles from "../styles/Auth.module.css";
export default function Auth() {
const [isRegistering, setIsRegistering] = useState(false);
const [username, setUserName] = useState(false);
const [password, setPassword] = useState(false);
const toggleIsRegistering = () => setIsRegistering(!isRegistering);
View handleRegister.js
const handleRegister = () => {
const user = new Parse.User();
user
.save({
username,
password,
})
.then(() => {
handleLogin();
View handleLogin.js
const handleLogin = () => {
Parse.User.logIn(username, password).then((user) => {
console.log(`successfully loged ${user.get("username")}`)
});
};
View index.js
export default function Home() {
const router = useRouter();
//..rest of the code