Skip to content

Commit

Permalink
Merge branch 'develop' into dev-landing
Browse files Browse the repository at this point in the history
  • Loading branch information
yusufginanjar committed Sep 30, 2022
2 parents 9f6cf79 + 018e052 commit 1181d5a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions components/navibar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useSelector, useDispatch } from "react-redux";
import { login as _login, logout } from "../store/loginSlice";
import { logout as stateLogout } from "../store/authSlice";


export default function Navibar() {
const [user, setUser] = useState(null);
const auth = getAuth();
Expand Down
12 changes: 10 additions & 2 deletions pages/login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { useRouter } from "next/router";
import React, { useEffect, useState } from "react";
import { useDispatch } from "react-redux";
import { Form } from "react-bootstrap";
import { signInWithEmailAndPassword, getAuth } from "../firebase/clientApp";
import { signInWithEmailAndPassword, getAuth, ref, getDatabase, onValue } from '../firebase/clientApp';
import { login as stateLogin } from '../store/authSlice';
import { useDispatch } from 'react-redux';
import Swal from "sweetalert2";
import styles from "../styles/Login.module.css";

Expand Down Expand Up @@ -33,7 +35,13 @@ export default function SignIn() {
useEffect(() => {
auth.onAuthStateChanged((user) => {
if (user) {
router.push("games");
router.push('games');
const db = getDatabase();
const dataRef = ref(db, '/users/' + user.uid);
onValue(dataRef, (snapshot) => {
const data = snapshot.val();
dispatch(stateLogin(data))
});
}
});
});
Expand Down
22 changes: 16 additions & 6 deletions pages/register.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import React, { useState as _useState } from "react";
import { Form } from "react-bootstrap";
import { uid } from "uid";
import { useRouter as _useRouter } from "next/router";
import Swal from "sweetalert2";
import React, { useState as _useState } from 'react';
import { Form } from 'react-bootstrap';
import { uid } from 'uid';
import { useRouter as _useRouter } from 'next/router';
import { login as stateLogin } from '../store/authSlice';
import { useDispatch } from 'react-redux';
import Swal from 'sweetalert2';

import {
createUserWithEmailAndPassword,
getAuth,
ref,
set,
getDatabase,
} from "../firebase/clientApp";
onValue,
} from '../firebase/clientApp';
const registerState = {
username: "",
password: "",
Expand Down Expand Up @@ -38,6 +42,7 @@ export default function signup() {
const { name, value } = e.target;
setUser({ ...user, [name]: value });
};
const dispatch = useDispatch();
const handleRegister = async () => {
if ((username, password, email === "")) {
await Toast.fire({
Expand All @@ -63,6 +68,11 @@ export default function signup() {
bio,
}
);
const dataRef = ref(db, `/users/${auth.currentUser.uid}`);
onValue(dataRef, (snapshot) => {
const data = snapshot.val();
dispatch(stateLogin(data))
});
await Toast.fire({
icon: "success",
title:
Expand Down

0 comments on commit 1181d5a

Please sign in to comment.