# Chat Interrupts in Action: AI Login Flow with Vercel AI SDK ## Metadata - **Published:** 5/7/2025 - **Duration:** 11 minutes - **YouTube URL:** https://youtube.com/watch?v=xUKnWPh1fac - **Channel:** nerding.io ## Description In this video, we build a seamless AI-powered login flow using the Vercel AI SDK with chat interrupts—so your agent knows when to pause, prompt the user to log in, and resume the conversation with full context. This pattern unlocks secure, personalized experiences in your AI apps. Perfect for when your chatbot needs access to tools like Google Calendar, Notion, GitHub, or any private data source. 🧠 What You’ll Learn: ✅ How to implement chat interrupt events with Vercel AI SDK ✅ Triggering login during a live AI chat session ✅ Resuming the conversation with updated context ✅ Managing user sessions, tokens, and context injection ✅ Creating AI apps that are both interactive and secure 💡 Why This Matters: Most AI apps ignore auth—or bolt it on as an afterthought. This approach puts auth at the center of the conversation, letting your AI agent dynamically respond based on who the user is and what they’ve connected. 🧱 Stack: - Vercel AI SDK - Next.js (App Router) - Auth0 🔗 Resources & Links: 📘 Vercel AI SDK: https://sdk.vercel.ai 🔐 Auth0: https://auth0.com/ai/docs/check-google-calendar-availability 🧠 Text Yourself App: https://textyourself.app 📩 Newsletter: https://sendfox.com/nerdingio 📞 Book a Call: https://calendar.app.google/M1iU6X2x18metzDeA 📌 Chapters: 00:00 Intro 00:22 Setup 04:11 Code 07:57 Demo 11:41 Final Thoughts 💬 What tool would you connect to your AI chat experience? Calendar, CRM, Notion? Drop it in the comments! 👇 👍 Like & Subscribe for more AI chat, agent workflows, and real-time interaction patterns! ## Key Highlights ### 1. AI-Powered Authentication Interrupts Using Vercel AI SDK with Ozero allows for authentication interrupts within GenAI workflows, enhancing user experience. ### 2. Dynamic Scope Acquisition The demo shows how to acquire calendar scopes dynamically within the chat flow, rather than upfront during initial login. ### 3. Interrupt-Driven Execution Vercel's 'execute with interrupts' feature pauses the LLM execution to handle authentication and resumes seamlessly afterwards. ### 4. Federated Authentication Flow Leveraging offzero to federate the access to the Google Calendar API, requesting additional scopes on demand. ### 5. NexJS and Firebase Boilerplate The presenter mentions a Firebase and Nex.js starter kit with AI-powered components and built-in prompt instructions for content generation. ## Summary ## Video Summary: Chat Interrupts in Action: AI Login Flow with Vercel AI SDK **1. Executive Summary:** This video demonstrates how to implement authentication interrupts within AI chat applications using the Vercel AI SDK and Auth0. By leveraging "chat interrupts," the AI agent can dynamically pause the conversation, prompt the user to log in and grant necessary permissions (like calendar access), and then seamlessly resume the conversation with updated context. **2. Main Topics Covered:** * **Introduction to AI-Powered Authentication Interrupts:** Using the Vercel AI SDK to handle authentication within GenAI workflows. * **Dynamic Scope Acquisition:** Demonstrating how to request specific scopes (e.g., Google Calendar) during the chat flow, rather than upfront at initial login. * **Implementation with Vercel AI SDK:** Showing how to use Vercel's 'execute with interrupts' feature to pause LLM execution for authentication. * **Federated Authentication Flow:** Utilizing Auth0 to federate access to the Google Calendar API and request additional scopes on demand. * **Code Walkthrough:** Reviewing the necessary code components in a Next.js application, including the interrupt handler, the Google authentication process, and the chat API route. * **Demo:** Demonstrating the chat interrupt in action, including the authentication popup and the resumption of the conversation after authentication. **3. Key Takeaways:** * Implementing chat interrupts with the Vercel AI SDK and Auth0 allows for dynamic authentication and permission handling during a chat session. * This approach enhances user experience by only requesting necessary permissions when needed. * The 'execute with interrupts' feature pauses the AI model, facilitating a seamless transition to authentication. * Federated authentication, like Auth0, simplifies managing user credentials and permission scopes. * The demo application used Next.js and highlighted how to integrate the interrupt system into a chat interface. **4. Notable Quotes or Examples:** * "This approach puts auth at the center of the conversation, letting your AI agent dynamically respond based on who the user is and what they’ve connected." * Demo of the AI agent prompting the user for calendar access mid-chat. * Explanation of the importance of the `interrupt` parameter to define when the tool executes the authentication component. * Mention of "Firebase and Nex.js starter kit with AI-powered components and built-in prompt instructions for content generation" as a related project (TextYourself App). **5. Target Audience:** * AI developers building chat applications with secure data access. * Developers interested in learning about AI authentication strategies. * Engineers seeking to improve user experience with dynamic permission requests. * Individuals curious about using the Vercel AI SDK for advanced AI agent workflows. ## Full Transcript Hey everyone, welcome to Nering I.io. I'm JD and today we're actually going to continue our journey into authentication with Genai apps. Specifically, we're going to look at how we can use Verscell AI and how with Ozero you can actually add interrupts so that you can authenticate in your your workflow itself. And with that, let's go ahead and get started. All right. So in this one, what we're going to be doing is we're actually going to be using Ozero and Verscell AI to actually build and uh pull our calendar information, but we're going to try two different ways. We are going to look through the first way that we did uh the other day and kind of just step through how you can do this in Nex.js. U one of the other cool things is they actually have a fastjs uh implementation as well. So, if you're looking for Python, you can actually use this stack instead. Um, but what's cool about this blog is that it gives you kind of a step-by-step checklist of how you need to go through and create your application. So, we've actually already done this in the previous video. So, I'm not going to go through that this time, but it's a really good tool to kind of leverage. And so what you can see is that in this one we're going to use all just versel. There's no langraph and we're uh the first way that this blog actually shows you is you're you're just going to connect. So when you log into the application, it's actually going to store your scopes and then you're going to have your credentials and you're able to just hit the API. However, what we want to do is we want to try and do an interrupt. And so what we're going to do is they also have this other how-tos and it's check your Google calendar availability. This one's a little bit different. We're still going to use JavaScript. You can see that they have all these different text stacks. So AI the AI SDK is what we're going to use. Last time we did Langraph. Again, I really like Genkit. Some of the prompt stuff that they're doing is super cool. Um, I actually put together a boiler plate uh and uh definitely think you should check them out. I love that this is gaining traction. But Versel is still really popular. And so what we're going to do is we're actually going to go through this build our own application and we're going to uh try and do an interrupt and see see what we get. So in here, the first thing that it's telling you to do is uh so there's no repo for this. I just kind of started everything from scratch and um we'll kind of look at the code along with real quick everyone. If you haven't already, please remember to like and subscribe. Also, I wanted to show you a gen kit boilerplate that I've been working on. Real quick, this is another project that I'm working on. It's a Firebase and Nex.js JS starter kit that comes with AI powered apps. And so what this allows you to do is get up and running with Firebase, Nex.js, and Genkit as well as pre-built AI components. So some of the things that I focused on were the ability to actually start with uh AI first mindset and built-in prompt instructions so that you can actually build new features, build new blog posts, build documentation and actually integrate directly into a chatbot that is built with a chat interface as well as content generation and different prompts. So, if you sign up now, there's actually a discount going on where you can get 90% off and this will fluctuate by uh this also comes with a social proof which allows you to do dynamic discounts. Right now, we're offering 90% off. So, definitely check it out and don't forget to like and subscribe. And with that, let's get back to it when we're building this. So, if we pull the code up, the first thing it's telling you to do is go down here and put in your O. Uh, you need to put in your O zero. So, go ahead and install that with the Nex JS Ozero piece, but it's telling you to put in this O uh O0-I in the root of your folder. Right along with your middleware, you also need to put in a Google off folder. And again, this is where it's going to have this federated connection through an offzero AI interrupt. And what that's going to do is it's going to basically check, do you have are you authenticated? And if not, it'll actually give you a component uh to to go uh fill out or use to log in. And so we've done this. Uh, now it's telling us to actually integrate a tool. So if we go back to our codebase, you can actually see that we're using this check user. And mine's a little different. I in order to get it to work, I actually had to do some transformation, but you should be able to drop drop in that tool. And uh this will give you the ability to call out to the AI calendar. And one thing to note is if you actually look at the u the the information that it's trying to call out to, it's a little bit different. So, uh just something to keep in mind when we uh look at our our calendar information, right? So, right here, it's calling out to a specific scope. So, this is a scope that is outside of our off that we signed up for when we were setting up our uh O zero implementation. And that's what's kind of making this unique is this is a scope that's outside of the default ones that we can leverage in Ozero. So now that we have our tool, we have our calendar information uh and our syncs, we're going to go ahead and build our route. There's some key differences that we will look at from uh before. First, this thread ID is super important. Also, this execute with interrupts. So this with interrupts is actually going to allow us again to actually put in an element and allow us to uh to authenticate. Next, we're going to add the component that we actually want to trigger that says uh go ahead and um you know do your authentication and then we basically just have a chat. Um, again, and the most important thing though is you need to have this interrupt so that when it sees a tool, it knows what tool and then it's going to tell it to connect the widget. So, you can kind of build your own chat and I'll I'll show you mine, but um this is also super important. So now when we go and run this, we have our route. We're basically giving it some context of what today's date is. Uh telling it, you know, that I want to be able to um that you're a family friendly calendar assistant and to basically just tell me if I'm busy or not, otherwise I error out. So let's go ahead and run this. So, I'm just going to do again this is just a a regular So, again, this is just a regular uh Next.js app. I went ahead and added an off uh landing page so that I can still log in. So, again, this is still using the same uh application that we built in the last one. You can see there's nothing here that says that it is looking for the busy scope. Um, but this is going to give us access as as it did the other one. And I just used this because it was an easy way to authenticate the experience. All right. So now I have my custom chat window. We can see that I'm pulling in my basic information. And what we're going to do is we're actually going to try and get an interrupt and see what it looks like. So, I've noticed that I it's still a little buggy for me um and and how I programmed it, but like what I noticed is I need to trigger a uh an initial response so that I can get an ID. Cool. And so now that I have like this initial message, I'm going to go ahead and uh just paste in am I free on Wednesday at 10:30 knowing that I'm busy and see what we can get as a response. Cool. So now we're getting the interrupt here, right? It knows that we don't have access to that scope of of calendar busy. And so we're going to go ahead and run a check. What this should do is actually do a popup and give us the ability to get that additional scope. Uh so you can see this is a bit different than it was before. We're go ahead and allow again very similar because we're going back through off zero and okay. So cool. So you can see that the uh the piece disappeared. I'm noticing like sometimes I get a response and sometimes it's slow. So as you just saw it uh Okay. So, it didn't convert the time correctly, but it did at least pick up the time and then converted it uh converted it back. So, uh but this is super cool, right? We were able to pull back from our calendar and we were able to see uh that information. So, if you want to understand a little bit more, you can actually look at the logs that are coming back. So don't worry about the the cross policy pieces, but what I wanted to show is when it's building when it's building and then this calling resume and this popup close. So if we go back and look at our code and we look at we have information here and we're looking at this popup these federated uh functions for our interrupt our off and our finish are what's happening in our popup. So once this is closed, it is looking for the information to come back and say on finish is a function. This calling on finish and sending on finish and calling on resume and that calling on resume is actually sending us the ability to then pull information from our calendar. So we had that interrupt. It went back to the system. It then resumed its place in in state and the LLM continued to give its result which is super super cool. It means that we don't necessarily have to authenticate right from the get-go and we can actually authenticate into our application. All right, that's it for us today everyone. What we went through is how you can actually wire up for cell AI so that you can fire off interrupts to actually p authenticate your agentic flows. And with that, happy nerding. --- *Generated for LLM consumption from nerding.io video library*