This video has been updated: kzbin.info/www/bejne/eIi4mml4iJ6Ha7s The updated version is much better so please watch that one instead of this video.
@jessejulian9069 Жыл бұрын
Hey Tom whats the difference between this video and the updated one? Is there anything wrongn with this one? The other one seems more complex and longer too
@degraphe88243 жыл бұрын
This is what I call typescript speed run. Great tutorial. I feel though, that it's better to type these things out for the more intermediate or junior Software Dev Folk. since it is an Auth lesson on Typescript majorly, most people coming here are probably intermediate or junior
@johnyepthomi892 Жыл бұрын
It is a speed run and juniors will have to sweat a bit to connect the dots.
@swatireddy68223 жыл бұрын
Hey Tom, doing great work.☺️ Please continue do such video which will help others to learn.
@rohitpandit32673 жыл бұрын
its been less than 5 minutes and already subscribed you, great video bro
@TomDoesTech3 жыл бұрын
Thank you so much! I am redoing this video and it's going to be 10 times better than this one, should be out next week :)
@EduardoHernandez-ux6gg3 жыл бұрын
The best tutorial of Node whit Ts, thx bro!! from Mexico
@TomDoesTech2 жыл бұрын
Glad it helped!
@bonarhymetechhub77862 жыл бұрын
Hello @tomdoestech, thank you very much for the content. However, there is a suggestion I want to make: Say you want to build the login functionality please do not start from the routes, it creates some kind of confusion. Instead you could do this: 1. Start from the various utilities 2. Build your validation schema 3. Build your service 4. Then build the routes This way, it will be easy to grasp.
@bikramjeetsingh49433 жыл бұрын
Great content, Brother!! Really like your typescript stuff
@TomDoesTech3 жыл бұрын
Thank you so much :)
@osaigbovoemmanuel12 жыл бұрын
Great tutorial! The tutor has a great understanding of RESTful APIs 👌
@akademidevid3 жыл бұрын
Awesome. You're doing great! Make another like this
@sandeepgamot45852 жыл бұрын
Wow I've never seen such sophisticated use of Postman, maybe you can make a video of your workflow with Postman
@bifdiogo3 жыл бұрын
Greetings from Brazil! Great job!
@noadevamshmanoj36183 жыл бұрын
Hey tom love your work ❤❤
@TomDoesTech3 жыл бұрын
Thank you so much :)
@yousuf4you2 жыл бұрын
This is a very thankful and helpful video....Thanks
@emekarr3 жыл бұрын
Fingers crossed on this. Hope it helps me.
@TomDoesTech3 жыл бұрын
Let me know if you have any questions
@akashshrestha013 жыл бұрын
great more videos on ts + node plz
@eternalprogramming35033 жыл бұрын
Thanks for the informative video! I think I'll be using this controller-service type system now
@mehmetilhan60832 жыл бұрын
Thanks a lot.I learned a lot ot things from this video.
@TomDoesTech2 жыл бұрын
Glad to hear that!
@Jack1430.3 жыл бұрын
Looks great, Im starting the project right now
@TomDoesTech3 жыл бұрын
Good luck Jackie! Please let me know how you get on with it.
@Jack1430.3 жыл бұрын
@@TomDoesTech thanks for your quickly answer, Ill be back for comment how its going! Thanks another time!!
@bkironas54733 жыл бұрын
Thanks for this video. I'm really new to Typescript coming from a C# background. I've been finding it hard to switch from OOP to functional programming, and I'm finding your video really helpful. One thing I noticed is that you dont really specify the return types for any of your functions. Is that standard practise with TS? Personally I believe that you should be able to look at a function and know exactly what's expected to go into it, and exactly what's expected to come out of it (obviously TS makes this a little less definitive with union types, but you still have an idea which type to expect).
@TomDoesTech3 жыл бұрын
I generally don't specify the output, which is probably bad practice. If your functions are pure and you specify the input, TS generally does a good job of implicitly specifying the output. I think it depends on the function and what you find useful.
@presidentialproductions84642 жыл бұрын
B Kironas Thanks for the input! I'm coming to this video with the same background and your comment made me sure I would learn from this video.
@Krior072 жыл бұрын
any idea how to solve this: Namespace '"mongoose"' has no exported member 'HookNextFunction'.
If someone getting printPretty error just put this in logger transport:{ target:"pino-pretty", options:{ colorize:true } },
@Scetils3 жыл бұрын
Solid again. Can you explain the reason why you set the newAccessToken generated from the expired refresh token to the "x-access-token" header but the initial access token uses the "authorization" header?
@TomDoesTech3 жыл бұрын
Hmmm that sounds like a mistake, the access token should always go in the authorization header.
@Scetils3 жыл бұрын
@@TomDoesTech Yeah I know what was confusing me. My bad. You're attaching the token to the out going/response headers.
@TomDoesTech3 жыл бұрын
@@Scetils I'm glad you figured it out :) When I was first learning about REST APIs the concept of incoming and outgoing requests really confused me. Unfortunately, KZbin didn't have much good content on the topic then.
@lucasgabule3 жыл бұрын
Awesome Tut.
@TomDoesTech3 жыл бұрын
Thank you so much :)
@lucasgabule3 жыл бұрын
@@TomDoesTech Better than udemy :)
@alxz113 жыл бұрын
Great work dude!! i see u use yup in request validation, i have a question how to validate if requested email is already used (unique email)?
@TomDoesTech3 жыл бұрын
If you have a unique flag on the email field in the mongoose model, MongoDB will enforce unique emails.
@viewer50993 жыл бұрын
Hi Tom, could you explain why you assign posts their own postId fields and not use the automatically generated id from Mongoose instead? I would also like to know what you would advise to do to prevent a malicious user from saturating the database with fake users? thank you in advance
@cali4484 Жыл бұрын
17:22 Is there an advantage in calling method "hashSync" over method "hash" ?
@vinayaknaik98842 жыл бұрын
great
@sandeepb83513 жыл бұрын
Hi Tom, great tutorial, I have a question why we use DocumentDefinition?, Also when should we use curly braces({ }) like here, import Post, { PostDocument } from "../model/post.model";
@TomDoesTech3 жыл бұрын
DocumentDefinition with your interface best matches when the model.create method takes as arguments. As for the imports, the bit outside the {} is a default export, while the but property inside is a named export. It's like importing using object destructing.
@manojrawat57566 ай бұрын
Sir I am not able to import {DocumentDefination} from mongoose
@fkarg103 жыл бұрын
I'm trying to follow along, and I got a very weird error at 7:31 (console.log -> log.info), as log was undefined. I just couldn't figure it out. Seems like it was due to running `npm run build` at some point, and the only change needed was to remove an auto-generated src/app.js
@성이름-k4r8j2 жыл бұрын
3:41 start setting
@mohammadandhika40282 жыл бұрын
what font do you use in your vscode ?
@muthukumarkamatchi18952 жыл бұрын
It’s very useful for me.. As I connect the database, it gives db error. Kindly help me solve this issue
@raymartpamplona91223 жыл бұрын
I think you forgot the part to add a clip of creating the model for the Post collections hehe
@naufaldbei42343 жыл бұрын
Im on the delete section of the video, in the delete section part do you put the accessToken on the headers.authorization? im still confused in this part...
@naufaldbei42343 жыл бұрын
yep it turns out my accessToken is always undefined on deserializeUser.ts, where do you put the accessToken after giving it back to the user in createSessionHandler?
@TomDoesTech3 жыл бұрын
You put it in the authorization header. There is a special section for it in postman, or you can create a header called `Authorization`.
@ilhamtanpasaldo Жыл бұрын
27:15
@dhanushreddy48362 жыл бұрын
import config from "config" this direct import did not work for me,,, how should i make it work
@TomDoesTech2 жыл бұрын
I have no idea, you haven't told me anything that would help me provide a solution
@dhanushreddy48362 жыл бұрын
@@TomDoesTech can you please provide me your linkedin profile link.. so that i can connect there.
@TomDoesTech2 жыл бұрын
@@dhanushreddy4836 no?
@Arun991783 жыл бұрын
Not works with "mongoose": "^6.0.2", version. getting error.
@TomDoesTech3 жыл бұрын
That's a shame
@glennmarkflores51983 жыл бұрын
works for me somehow, done some workaround also, uninstall @types/mongoose. the latest versions come with built-in types
@mehulmorker22913 жыл бұрын
HI @TomDoesTech I have use delete session api and that make my session valid: false. But with the same token I am able to call create post api. I think need to make some changes in deserialize middleware
@TomDoesTech3 жыл бұрын
When you delete the session or change valid to false, you're making sure the refresh token can't be used to generate another access token, but the current access token will still work. This is why the access tokens should have a short TTL. If you want to use the delete session like a logout, also remove the access token from the user.
@aliyyil90352 жыл бұрын
bro why we need private kay? i did understand, can u explain this
@TomDoesTech2 жыл бұрын
Private keys are secrets for signing tokens. You then check with the public key to verify if the token was signed with the correct private key. Look up PGP encryption
@aliyyil90352 жыл бұрын
@@TomDoesTech where to sign tokens. When we use it in rest ful api. Can it work without sing or private key?
@behroozsayah16793 жыл бұрын
I've faced to an issue with typescript and type checking. In "session.controller" I'm getting the following error: "Property '_d' does not exist on type 'false'" I've added the following type checking to the if clause but it did not help. if(typeof user === 'boolean) res.status(401).send('Invalid username or password')
@behroozsayah16793 жыл бұрын
I have added the following but I don't know that it is the best practice or not. const session = await createSession((user as UserDocument)._id, req.get('user-agent') || '') const accessToken = createAccessToken({ user: user as UserDocument, session})
@TomDoesTech3 жыл бұрын
That's a very weird problem. If you send me a link to the repo I can take a look.
@bhootuncle32693 жыл бұрын
Does all api are rest or soap api Is there nothing like only api (pure api without any type)
@TomDoesTech3 жыл бұрын
APIs are just interfaces that expose the internal workings of a system. They don't always communicate over a network like REST, SOAP & GraphQL APIs. Node.js for example has a standard library and you interact with it through its API. Another example is React, when you call useState for example that's part of React's API.
@bhootuncle32693 жыл бұрын
@@TomDoesTech thanks for your prompt reply
@bobvandoorn87613 жыл бұрын
Did I misunderstood, or are u sending with every request the accessToken and the refreshToken? And not like only sending the refreshToken when de accessToken is invalid.
@TomDoesTech3 жыл бұрын
Yeah, send it with every request to make it as seamless for the user
@bobvandoorn87613 жыл бұрын
@@TomDoesTech Can you explain why not just using 1 token? I have the feeling it doesn't make sense to use two different tokens in this manner. I understand it is not the main focus of this video, just wondering. (great video btw ;) )
@TomDoesTech3 жыл бұрын
@@bobvandoorn8761 The two tokens have two different purposes, one grants the user access to the resource, the other, given certain conditions, grants the user access to another access token.
@Holaszyd13 жыл бұрын
Help @TomDoesTech i keep getting this error: "mongoose"' has no exported member 'HookNextFunction'
@TomDoesTech3 жыл бұрын
Have you installed @types/mongoose?
@Holaszyd13 жыл бұрын
@@TomDoesTech yes it is installed already
@glennmarkflores51983 жыл бұрын
try this ... async function ( this: UserDocument, next: (err?: Error | undefined) => void ) ....
@corentintruffaut72913 жыл бұрын
Hi there ! First, ty for the content. It helps me to understand some stuff. However i got an issue adapting your exemple to my code. Something i never encounter comes to me ˆˆ -> I write service and model just as you can, but, when i call .create() method with input as parameters, datas disappear.. I got them in service function but they don't pass to .pre('save') method. I know it's small, but any idea what's going on ?
@TomDoesTech3 жыл бұрын
Interesting, if you can share a repository I am happy to take a look
@corentintruffaut72913 жыл бұрын
@@TomDoesTech Ty for you'r concerne, i figure it out but i don't understand why it happened.. I used arrow function for async function in .pre('save'). I just rewrite it with classic function and it finally works. Do you know the difference between this two ?
@TomDoesTech3 жыл бұрын
@@corentintruffaut7291 Yes, it has to do with scope and closures. Using the function keyword sets scope to the parent function, allowing you to get access to the `this` keyword.
@corentintruffaut72913 жыл бұрын
@@TomDoesTech Ok, ty for the explanations !
@NathanielBabalola3 жыл бұрын
Thanks a lot for this video, i am just trying to understand something. you said if(!accessToken) return next(); , why though? thought it should be access denied at that point if there is no accessToken in the request and return a 403
@TomDoesTech3 жыл бұрын
You need to consider the path that the data takes. That middleware is run first, so if there is no access token when it gets to the requireUser middleware, the user will be null and a 403 will be sent. You don't want to return a 403 in the deserializeUser middleware because then the user has to be logged in for every request, so how will they login or register in the first place.
@TomDoesTech3 жыл бұрын
If that doesn't make sense I can make you up a flow diagram to help visualize the flow.
@@NathanielBabalola There is actually a diagram on the GitHub repo
@seanhuggins53823 жыл бұрын
@@TomDoesTech Do you need to have deserializeUser middleware for every route? Could you not combine requiresUser and deserializeUser into one middleware function and only place it on protected routes?
@ravincristiano3 жыл бұрын
where can I get Private kEY?
@TomDoesTech3 жыл бұрын
Google "generate public and private keys online".
@ravincristiano3 жыл бұрын
@@TomDoesTech is it okay if i work with the same key you used here?
@TomDoesTech3 жыл бұрын
@@ravincristiano Yup, I think I committed it to GH
@audunhilden2 жыл бұрын
please man, stop copying everything all the time you've got some good tutorials, so please start typing them out or at least giving us 5 seconds to pause i need to pause and always skip backwards to see what you pasted
@TomDoesTech2 жыл бұрын
I've posted a lot of tutorials since this one and I haven't copied since this one, so I'm not sure how I stop doing something that I stopped doing over a year ago
@audunhilden2 жыл бұрын
@@TomDoesTech how would I know? just trying to give you a tip good work
@mdjahidulislam92053 жыл бұрын
how to deploy it?
@TomDoesTech3 жыл бұрын
That's a very broad question that has hundreds, if not thousands of answers. If it's a specific method you're after, the best thing I can point you to is this video: kzbin.info/www/bejne/aKCxpJ2vlqh8qKs
@ravincristiano3 жыл бұрын
getting 403 error while creating a post.
@TomDoesTech3 жыл бұрын
Perfect! The Auth system works
@ravincristiano3 жыл бұрын
@@TomDoesTech how to solve this error??
@TomDoesTech3 жыл бұрын
@@ravincristiano Send the request with a valid JWT
@ravincristiano3 жыл бұрын
@@TomDoesTech I tried with a refresh token but still the same error.. post: localhost.../api/posts headers: key: x-refresh value: refreshToken send 403 forbidden
@devMhamza0073 жыл бұрын
@@ravincristiano add the access token in auth -> bearer token
@wahyuramadhan93163 жыл бұрын
is there anyone know why my get(req, "user") is returned undefined ? so i cant deleting session or anything passing requiresUser middleware ?
@TomDoesTech3 жыл бұрын
Have you tried logging the user object just before you do req.user = user?
@wahyuramadhan93163 жыл бұрын
@@TomDoesTech yes sir, I have log in then copy paste x-refresh from refresh token, what should I do next ?
@TomDoesTech3 жыл бұрын
@@wahyuramadhan9316 No, I mean using console.log to log the user object to make sure it's being deserialized properly.
@wahyuramadhan93163 жыл бұрын
in what file sir that i must logging the user object ?
@TomDoesTech3 жыл бұрын
@@wahyuramadhan9316 in the deserialize middleware
@binitrupakheti42463 жыл бұрын
Dude you're going way too fast.
2 жыл бұрын
literally first line of tutorial yarn : The term 'yarn' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. LMAO
@TomDoesTech2 жыл бұрын
You have to install yarn to be able to use it, otherwise you can use npm
@TomDoesTech2 жыл бұрын
This tutorial is not for beginners, it says at the start its for junior to mid-level devs
@shub22611 ай бұрын
Idk you edited this video yourself or from a editor but it was just a big mess
@TomDoesTech11 ай бұрын
Sorry to disappoint you. The pinned comment and description have a link to an updated version
@FutureIsAmazing5693 жыл бұрын
editing is beyond terrible
@TomDoesTech3 жыл бұрын
Thanks for the feedback. I'm a software developer trying to learn how to make videos. So I know my editing skills are bad but I am trying to improve them. I'll keep working on it. Got any tips on how I can improve?
@noboss37363 жыл бұрын
@@TomDoesTech I think he means that sometimes between cuts your voice is cut off a bit, like at 14:45 for example. But apart from that, I think the video is great! It must be annoying to have such a comment without any further explanation, when you are just trying to help other people and doing your best. So in my opinion great video and keep up the good work :)
@TomDoesTech3 жыл бұрын
@@noboss3736 Yeah i think I need to edit the noise gate I have setup
@poweredcity37043 жыл бұрын
@@TomDoesTech Hey great video! But I believe it would be better if you typed it out instead of cutting the big code parts out, when you do that with a paste of big code it encourages me to copy/paste. And I rather actually learn stuff then do that.
@TomDoesTech3 жыл бұрын
@@poweredcity3704 Thanks for the feedback but I'm curious as to why you think that. It would be very boring watching me type and not talking while I typed everything out. I think it's much better if I paste the code and explain it, then you can copy it with an understanding of what it does.
2 жыл бұрын
I can't even connect to mongoose as i get an error on useNewUrlParser: true, TSError: ⨯ Unable to compile TypeScript: src/db/connect.ts:10:7 - error TS2769: No overload matches this call. Overload 1 of 3, '(uri: string, callback: CallbackWithoutResult): void', gave the following error. Argument of type '{ useNewUrlParser: boolean; useUnifiedTopology: boolean; }' is not assignable to parameter of type 'CallbackWithoutResult'. Object literal may only specify known properties, and 'useNewUrlParser' does not exist in type 'CallbackWithoutResult'. Overload 2 of 3, '(uri: string, options?: ConnectOptions | undefined): Promise', gave the following error. Argument of type '{ useNewUrlParser: boolean; useUnifiedTopology: boolean; }' is not assignable to parameter of type 'ConnectOptions'. Object literal may only specify known properties, and 'useNewUrlParser' does not exist in type 'ConnectOptions'. 10 useNewUrlParser: true, ~~~~~~~~~~~~~~~~~~~~~ at createTSError (F:\Programas\Coding\Mobile_Projects\BackEnd\BackEndAutoSense ode_modules\ts-node\src\index.ts:820:12) at reportTSError (F:\Programas\Coding\Mobile_Projects\BackEnd\BackEndAutoSense ode_modules\ts-node\src\index.ts:824:19) at getOutput (F:\Programas\Coding\Mobile_Projects\BackEnd\BackEndAutoSense ode_modules\ts-node\src\index.ts:1014:36) at Object.compile (F:\Programas\Coding\Mobile_Projects\BackEnd\BackEndAutoSense ode_modules\ts-node\src\index.ts:1322:43) at Module.m._compile (F:\Programas\Coding\Mobile_Projects\BackEnd\BackEndAutoSense ode_modules\ts-node\src\index.ts:1454:30) at Module._extensions..js (node:internal/modules/cjs/loader:1159:10) at Object.require.extensions. [as .ts] (F:\Programas\Coding\Mobile_Projects\BackEnd\BackEndAutoSense ode_modules\ts-node\src\index.ts:1458:12) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:827:12) at Module.require (node:internal/modules/cjs/loader:1005:19) { diagnosticCodes: [ 2769 ] }
@TomDoesTech2 жыл бұрын
Remove useNewUrlParser: true, you don't need it with the new version of mongoose
2 жыл бұрын
@@TomDoesTech thanks. i saw now you hyave an updated video, will watch that instead