prashant react basic understanding..
login karenge
email id and password .... kahan se jata hai....
jab koi bhi route dalte ho toh ten tarike se ja sakta hai...
url mein seedhe dal do ::: no 01
ya sidebar mein link hoga tab ayega
ya npm start se automatically hota hai..
yeh kuch case hain jab request hit hoti hai...
jab yeh request hit hoti hai toh kahan jata hai............
firsltly index.js in server.....
after that two options....
if router laga hua hai toh alag alag page kholo....
nai toh bydefault app.js se seedhe route chalega....
agar swtich nai dete hain toh ek hi bar mein sare routes render ho jate hain...
exact mein check karte hain ......ki slash hi hai kya.......
agar aapne switch nai lagaya toh apke sare routes render kar dega...
..........................................................
/login se.......
swtich pehla route de dega...
exact likha hua hai...toh fir exact lega ki .....login kahan likha hai uske age kuch bhi nai lega...
ar agar slash nai lete ho...
switch mein ehl
/login se check karke login ke page par jayega
login ka page reducer ke page par kam kar raha hai..
jab hum apna email password dalte hain toh woh backend ke apicontroller par jayega...+++++
++++++++++++ kaise jayega.....
api/v1/login ...url yeh bheja backend ke liye method post bheja.....
(kiske andar mein url bhejta hoon......) global path config ke andar.....ek constant bana rakha hai....
har bar ek api bhejte ho ap us api ko bhejne ke liye apko ek api base url ki jarurat hoti hai....
kyun hoti hai.....jab hum axios call karte hain toh request kaheen toh jayegi....toh wahan par api base url dena hota hai...
api ki request jati hai apke server par....
yahan se url se
yeh url append hota hai...
api ka url kya hai...
abhi frontend se ppoora bhejene pehle....
login ka page kholne ke liye ...sabse pehle route par
fir srvices par jaunga..
services mein jo function bana hoga login ka
.........................
function login(email, password) {
const subdomain = window.location.host.split('.')[1] ? window.location.host.split('.')[0] : false;
const requestOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify( { user: { email, password, subdomain } })
};
return fetch(`${BASE_URL}/sign_in`, requestOptions)
.then(handleResponse)
.then(user => {
// store user details and jwt token in local storage to keep user logged in between page refreshes
console.log("User Response", user.data)
if (user && user.status === 200) {
localStorage.setItem('user', JSON.stringify(user.data));
}
return user;
});
}
............................................
yahan se ......
rails ke ...base url par jayega....haan.....waheen par server par jakar hit marega....
fir rails ke route par jayega ==== kya check karega..
kaun sa controller ka method aur action route par check akrega...
ki kaun sa method aur action hai jis par mein isko bhej doon....
Imp:::::
folders mein agar rails mein kuch dal diya toh uske liye namespace use karte hain.....
ab jis controller mein hum gaye hain(session),...usmein jis controller se inherit kar rahe hain(api)
usmein check karna hoga ki kya hai aur kahan se aya ha kya aya hai....ek abr is api controller ko bhi check kar lo ek overview le lo ki kaun kauns function ismein bane hue hain kyun ki yeh fucntion session controller mein bhi use honge.....
ab
session controller ke create action par jakar check karenge ek ek line ko ki kya chal raha hai ...byebug alagaakr ya fr kaise bhi...code kya and kasie likha hai usko bhi smajhenge...
/.........................................
def create
# begin
return render json: {status: 401, data: {user: nil}, message: "Request Parameter not valid"} unless params[:user]
email = params[:user][:email]
password = params[:user][:password]
return render json: {status: 401, data: {user: nil}, message: "The request must contain the email and password."} unless email && password
@user = User.where(email: email).first
# @user = User.where(email: email).first unless @user
return render json: {status: 401, data: {user: nil}, message: "Invalid email or password"} if @user.blank?
return render json: {status: 401, data: {user: nil}, message: "Invalid email or password"} if not @user.valid_password?(password)
return render json: {status: 401, data: {user: nil}, message: "Invalid email or password"} if not _is_valid_account_for_subdomain
Comments
Post a Comment