Skip to content

Commit

Permalink
Merge pull request #1 from avirajsingh7/master
Browse files Browse the repository at this point in the history
AppWrite Backend Integration Of Login and Registration
  • Loading branch information
gupta-arpan committed May 24, 2023
2 parents b77b655 + aa60720 commit 590797c
Show file tree
Hide file tree
Showing 5 changed files with 427 additions and 374 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
"process": "^0.11.10",
"react-error-overlay": "6.0.9",
"tailwindcss": "^3.3.2",
"vite": "^4.3.2"
"vite": "^4.3.8"
}
}
7 changes: 7 additions & 0 deletions src/appwrite/appwriteConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Client, Account, Databases} from "appwrite";

const client = new Client();

client.setEndpoint('https://cloud.appwrite.io/v1').setProject('ProjectID');

export const account = new Account(client);
39 changes: 37 additions & 2 deletions src/components/LoginCard.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Link } from "react-router-dom";

import React,{ useState } from "react";
import {account} from '../appwrite/appwriteConfig';
import { useNavigate } from "react-router-dom";

function LoginCard(props) {

const navigate = useNavigate();
function handleRegisterButtonClick() {
props.isLoginCardVisible(prevValue => {
return !prevValue;
Expand All @@ -10,6 +14,24 @@ function LoginCard(props) {
return !prevValue;
})
}

const [user, setuser] = useState({
email:"",
password:""
})

const loginUser = async(e)=> {
e.preventDefault()
try {
await account.createEmailSession(user.email,user.password);
navigate('/find-restaurants');
} catch (error) {
console.log(error)
console.log("You were here")
}
}


return (
<div>
<div className="blur-background"></div>
Expand All @@ -36,6 +58,12 @@ function LoginCard(props) {
autoComplete="email"
required
className="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-primary sm:text-sm sm:leading-6"
onChange={(e)=>{
setuser({
...user,
email:e.target.value
})
}}
/>
</div>
</div>
Expand All @@ -57,6 +85,12 @@ function LoginCard(props) {
autoComplete="current-password"
required
className="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-primary sm:text-sm sm:leading-6"
onChange={(e)=>{
setuser({
...user,
password:e.target.value
})
}}
/>
</div>
</div>
Expand Down Expand Up @@ -90,7 +124,8 @@ function LoginCard(props) {
<button
type="submit"
className="flex w-full justify-center rounded-md bg-primary px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-hoverColor focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"
>
onClick={loginUser}
>
Login
</button>
</div>
Expand Down
57 changes: 56 additions & 1 deletion src/components/RegisterCard.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { useState } from "react";
import React,{ useState } from "react";
import logo from "../assets/logo/logo.ico";
import {account} from '../appwrite/appwriteConfig';
import { v4 as uuidv4 } from 'uuid';
import { useNavigate } from "react-router-dom";

function RegisterCard(props) {


const navigate = useNavigate();
function handleLoginButtonClick() {
props.isRegisterCardVisible((prevValue) => {
return !prevValue;
Expand All @@ -11,6 +17,36 @@ function RegisterCard(props) {
});
}

const [user, setuser] = useState({
name:"",
email:"",
password:""
})

const signupUser = async(e)=>{
e.preventDefault();
const promise = account.create(
uuidv4(),
user.email,
user.password,
user.name
)

promise.then(
function(response){
console.log(response)
navigate('/find-restaurants');

},
function(error){
console.log(error)
console.log("It is error")
}
)
}



return (
<div>
<div className="blur-background"></div>
Expand All @@ -37,6 +73,12 @@ function RegisterCard(props) {
autoComplete="name"
required
className="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-primary sm:text-sm sm:leading-6"
onChange={(e)=>{
setuser({
...user,
name:e.target.value
})
}}
/>
</div>
</div>
Expand All @@ -56,6 +98,12 @@ function RegisterCard(props) {
autoComplete="email"
required
className="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-primary sm:text-sm sm:leading-6"
onChange={(e)=>{
setuser({
...user,
email:e.target.value
})
}}
/>
</div>
</div>
Expand All @@ -77,6 +125,12 @@ function RegisterCard(props) {
autoComplete="current-password"
required
className="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-primary sm:text-sm sm:leading-6"
onChange={(e)=>{
setuser({
...user,
password:e.target.value
})
}}
/>
</div>
</div>
Expand Down Expand Up @@ -111,6 +165,7 @@ function RegisterCard(props) {
<button
type="submit"
className="flex w-full justify-center rounded-md bg-primary px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-hoverColor focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"
onClick={signupUser}
>
Create account
</button>
Expand Down
Loading

0 comments on commit 590797c

Please sign in to comment.