Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppWrite Backend Integration Of Login and Registration #1

Merged
merged 2 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
User Auth
  • Loading branch information
avirajsingh7 committed May 24, 2023
commit 5c3ea654e713f180b1881c01f9dcc1fdd6d566af
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('646b5e5b7caf699ef5f7');

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