0:00 Okay, so we have an auth guard in place that's 0:02 gonna make sure we're not showing 0:04 any of our protected routes to an unauthenticated user. 0:08 However, I also wanna introduce some functionality 0:11 that will redirect 0:12 the user if they're not authenticated back to the login 0:16 screen so that they can be prompted for credentials, log in or 0:20 sign up, and then become authenticated to actually 0:22 use our application 0:24 instead of just sitting on an empty page like this. 0:28 So the way I wanna implement this is to actually check all network requests, 0:33 and if any network request we make comes back with a 401 0:36 status code, we know we're unauthorized at that point, 0:40 and I 0:40 want to redirect the user back to the login screen. 0:44 And so another use case for this functionality is, for example, 0:48 if we've been logged in to the application for a long time 0:52 and our JWT is expired, well, then when we make 0:56 requests to our backend server, we'll get a 401 status code 1:00 back. And in that case, I also wanna redirect the user back to the 1:03 login screen. So this is gonna serve two purposes. 1:06 It's gonna make sure that whenever we get a 401 back from our 1:09 server, we'll get 1:10 redirected, and also when we visit a protected route, 1:13 we know we 1:14 automatically are making this query for me, 1:18 and so if this comes back with a 401, we know that we're 1:22 unauthorized, so we'll simply follow the same procedure 1:26 of 1:26 redirecting the user back to the login screen. 1:29 So to implement this, we can utilize the idea of a 1:33 link in Apollo Client. 1:35 So a link is gonna allow us to attach 1:38 functionality to our existing Apollo 1:42 Client that we have set up. So right now, this is our Apollo 1:46 Client, and we can essentially think of it like
The rest of the transcript is for members.
Sign in