Giter VIP home page Giter VIP logo

angular-10-role-based-authorization-example's Issues

Error in fake-backend.ts file while using it for Angular 14

Hi Sir ,
There are 2 errors showing in my Angular 14 project when I am trying to run your project in my pc..

// route function

function authenticate(){
        const { username, password} = body;
        const user = users.find(x => x.username === username && x.password === password);
        if(!user) return error('Username or password is incorrect');
        return ok({
            id: user.id,
            username: user.username,
            firstName: user.firstName,
            lastName: user.lastName,
            role: user.role,
            token: `fake-jwt-token.${user.id}`
        });
    }

Error 1 :
Argument of type '{ id: number; username: string; firstName: string; lastName: string; role: Role; token: string; }' is not assignable to parameter of type '{ id: number; username: string; password: string; firstName: string; lastName: string; role: Role; } | { id: number; username: string; password: string; firstName: string; lastName: string; role: Role; }[] | undefined'.
Object literal may only specify known properties, and 'token' does not exist in type '{ id: number; username: string; password: string; firstName: string; lastName: string; role: Role; } | { id: number; username: string; password: string; firstName: string; lastName: string; role: Role; }[]'.ts(2345)

I am getting above error for " [token :](token: fake-jwt-token.${user.id}) " this line...

2nd function under fake-backend.ts

 function getUserById(){
        if(!isLoggedIn()) return unauthorized();

        // only admins can access other user records 
        if(!isAdmin() && currentUser().id !== idFromUrl()) return unauthorized();

        const user = users.find(x => x.id === idFromUrl());
        return ok(user);
    }

Error 2 :
Object is possibly 'undefined'.ts(2532)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.