Snippets Collections
 <Button component={Link} to='/auth' variant='contained'color='primary'>SignIn</Button>
 const {page}=req.query;
    console.log(page);
    try {
        const LIMIT=6; 
        // limit can be used dynamically
        const startIndex=(Number(page)-1 )* LIMIT;//getting the starting index of all the posts
        // converting page to Number because we get string as query

        const total=await PostMessage.countDocuments({});
        const posts = await PostMessage.find().sort({_id:-1}).limit(LIMIT).skip(startIndex); //skipping all the previous pages from loading
        
        res.status(200).json({data:posts,currentPage:Number(page),numberOfPages:Math.ceil(total/LIMIT)});
    }
    catch (error) {
        res.status(404).json({ message: error.message });

    }
//backend
//api

export const getPostsBySearch=async  (req,res)=>{
    const {searchQuery , tags}=req.query; 
    try {
       const title=new RegExp(searchQuery,'i');
       const posts=await PostMessage.find({$or:[{title},{tags:{$in:tags.split(',') }}]})
       //here we get tags as an array so finding the specific tag by spliting tags using array, because we get the array as an object here using ",". or = search by title or tags .RegExp = regex.

       res.json({data:posts})
    //    i for ignoring case 
    } catch (error) {
        
    }
}
//actions
 
export const getPostsBySearch=(searchQuery)=>async(dispatch)=>{
    try {
        
        const {data:{data}}=await api.fetchPostsBySearch(searchQuery);
        console.log(data);
    } catch (error) {
       console.log(error); 
    }
}
//action in front end

export const getPostsBySearch=(searchQuery)=>async(dispatch)=>{
    try {
        const {data:{data}}=await api.fetchPostsBySearch(searchQuery);
        console.log(data);
    } catch (error) {
       console.log(error); 
    }
}
///eta bahire\\\
function useQuery(){
    return new URLSearchParams(useLocation().search)
}
/// then vitore\\\
const query=useQuery();
    const page=query.get(page)
    /// page name e kono query thakle tar value dibe\\\
import jwt from 'jsonwebtoken'
const auth=async (req,res,next)=>{
    try {
       const token=req.headers.authorization.split(''[1]);
       const isCustomAuth=token.length<500;
       let decodedData;
       if(token && isCustomAuth){
               decodedData=jwt.verify(token,process.env.SECRET);
              req.userId=decodedData?.id;
       }
       else{
        decodedData=jwt.decode(token);
        req.userId=decodedData?.sub;
       }
       next();
    } catch (error) {
        console.log(error);
    }
}
import bcrypt from 'bcryptjs';
import jwt from 'jsonwebtoken';
import user from '../models/user';

export const signin=async (res,req)=>{
 const {email,password} =req.body;
 try {
    const existingUser=await userfindOne({email: email});
    if(!existingUser) return res.status(404).json({message: 'user doesnot exist'});
    const isPasswordCorrect=await bcrypt.compare(password,existingUser.password);
    if(!isPasswordCorrect) return res.status(400).json({message: 'invalid credintials'});
    const token=jwt.sign({email:existingUser.email,id:existingUser._id},process.env.SECRET,{expiresIn:'1h'})
    res.status(200).json({result:existingUser,token})
 } catch (error) {
    res.status(500).json({message:'something went wrong'})
 }
}
export const signup=async (res,req)=>{

}
star

Tue Jul 19 2022 21:52:09 GMT+0000 (Coordinated Universal Time)

#javascript #nodejs #jwt #login
star

Mon Jul 18 2022 20:50:42 GMT+0000 (Coordinated Universal Time)

#javascript #nodejs #jwt #login
star

Sun Jul 17 2022 19:52:01 GMT+0000 (Coordinated Universal Time)

#javascript #nodejs #jwt #login
star

Sun Jul 17 2022 09:10:16 GMT+0000 (Coordinated Universal Time)

#javascript #nodejs #jwt #login
star

Sat Jul 16 2022 20:23:03 GMT+0000 (Coordinated Universal Time) https://www.youtube.com/watch?v=VsUzmlZfYNg&t=12191s

#javascript #nodejs #jwt #login
star

Wed Jun 01 2022 15:52:07 GMT+0000 (Coordinated Universal Time) https://www.cluemediator.com/login-app-create-login-form-in-reactjs-using-secure-rest-api

#reactjs #login
star

Mon Feb 14 2022 07:38:16 GMT+0000 (Coordinated Universal Time) https://alvinalexander.com/blog/post/postgresql/log-in-postgresql-database/

#login #postgres

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension