Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Who are vue? Authn in Vue, the important parts

Who are vue? Authn in Vue, the important parts

In the ever-evolving landscape of modern single-page applications, VueJS stands out, but it also presents us with challenges. Among them, authentication is a crucial one: ensuring the user's identity and securing their journey within your application. Fear not, though; we're here to guide you through these exciting frontiers.

In our session, we'll unravel the secrets of authentication in VueJS applications, making it a delightful learning journey for everyone while keeping the focus on the most important parts. We'll provide an overview of an authentication flow, break down each step, and demystify the role of JWT tokens in the process.

Whether you're a seasoned VueJS developer or just getting started, you're in for a treat. A dash of prior experience with user authentication certainly doesn't hurt, but it's optional. We welcome all, no prior knowledge is necessary – bring your curiosity and enthusiasm to explore the world of user authentication!

Ramona Schwering

February 29, 2024
Tweet

More Decks by Ramona Schwering

Other Decks in Technology

Transcript

  1. @leichteckig Who are Vue? // Import required libraries and create

    Express App ... const users = [{ ... }]; // Create a simple, mocked user // Login route app.post('/login', (req, res) => { const { username, password } = req.body.data; // Replace this with your database query to fetch user data const user = users.find((u) => u.username === username && u.password === password); // Simple mock response if (user) { res.status(200).json({ message: 'User is authenticated' }); } else { res.status(401).json({ message: 'Invalid username or password' }); } }) // Start the server... Stackblitz
  2. @leichteckig Who are Vue? // Import required libraries and create

    Express App ... const users = [{ ... }]; // Create a simple, mocked user // Login route app.post('/login', (req, res) => { const { username, password } = req.body.data; // Replace this with your database query to fetch user data const user = users.find((u) => u.username === username && u.password === password); // Simple mock response if (user) { res.status(200).json({ message: 'User is authenticated' }); } else { res.status(401).json({ message: 'Invalid username or password' }); } }) // Start the server... Stackblitz
  3. @leichteckig Who are Vue? // Import required libraries and create

    Express App ... const users = [{ ... }]; // Create a simple, mocked user // Login route app.post('/login', (req, res) => { const { username, password } = req.body.data; // Replace this with your database query to fetch user data const user = users.find((u) => u.username === username && u.password === password); // Simple mock response if (user) { res.status(200).json({ message: 'User is authenticated' }); } else { res.status(401).json({ message: 'Invalid username or password' }); } }) // Start the server... Stackblitz
  4. @leichteckig Who are Vue? // Import required libraries and create

    Express App ... const users = [{ ... }]; // Create a simple, mocked user // Login route app.post('/login', (req, res) => { const { username, password } = req.body.data; // Replace this with your database query to fetch user data const user = users.find((u) => u.username === username && u.password === password); // Simple mock response if (user) { res.status(200).json({ message: 'User is authenticated' }); } else { res.status(401).json({ message: 'Invalid username or password' }); } }) // Start the server... Stackblitz
  5. @leichteckig Who are Vue? // Imports… const routes = [

    { path: '/', component: Home }, { path: '/login', component: Login }, // Protected route { path: '/dashboard', component: Dashboard, meta: { requiresAuth: true }} ]; const router = createRouter({ history: createWebHashHistory(), routes }); export default router;
  6. @leichteckig Who are Vue? // Imports… const routes = [

    { path: '/', component: Home }, { path: '/login', component: Login }, // Protected route { path: '/dashboard', component: Dashboard, meta: { requiresAuth: true }} ]; const router = createRouter({ history: createWebHashHistory(), routes }); export default router;
  7. @leichteckig Who are Vue? //... app.use(cors({credentials: true, origin: ‘http://localhost:8080'})); //…

    // Login route app.post('/login', (req, res) => { //... if (!user) { res.status(401).json({ message: 'Invalid username or password' }); } const token = jwt.sign(...); res.setHeader('Set-Cookie', `user_token=${token}; HttpOnly;`); res.json({ user, token }); }) // Start the server...
  8. @leichteckig Who are Vue? //... app.use(cors({credentials: true, origin: ‘http://localhost:8080'})); //…

    // Login route app.post('/login', (req, res) => { //... if (!user) { res.status(401).json({ message: 'Invalid username or password' }); } const token = jwt.sign(...); res.setHeader('Set-Cookie', `user_token=${token}; HttpOnly;`); res.json({ user, token }); }) // Start the server...
  9. @leichteckig Who are Vue? Secure authentication is crucial Authn !=

    Authz Three factors to remember Implementation in Vue via libraries or tools