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
//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/';
}
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;
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([]);
const employee = new Parse.Object('Employee');
employee
.save({
username: employeeName,
email: employeeEmail,
password: employeePassword,
})
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);
};
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 }) {
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);
const handleRegister = () => {
const user = new Parse.User();
user
.save({
username,
password,
})
.then(() => {
handleLogin();
const handleLogin = () => {
Parse.User.logIn(username, password).then((user) => {
console.log(`successfully loged ${user.get("username")}`)
});
};
export default function Home() {
const router = useRouter();
//..rest of the code