The auth() helper returns the Auth object of the currently active user, as well as the redirectToSignIn() method. It includes a single method, protect(), which you can use to check if a user is authenticated or authorized to access certain parts of your application or even entire routes.
Only available for App Router.
Only works on the server-side, such as in Server Components, Route Handlers, and Server Actions.
auth.protect() can be used to check if a user is authenticated or authorized to access certain parts of your application or even entire routes. See detailed examples in the guide on verifying if a user is authorized.
The following example shows how to use redirectToSignIn() to redirect the user to the sign-in page if they are not authenticated. It's also common to use redirectToSignIn() in clerkMiddleware() to protect entire routes; see the clerkMiddleware() docsNext.js Icon for more information.
You can use auth() to check if isAuthenticated is true. If it's false, then there is not an authenticated (signed in) user. See detailed examples in the dedicated guide.
You can use auth() to check if a user is authorized to access certain parts of your application or even entire routes by checking their type of access control. See detailed examples in the guide on verifying if a user is authorized.
You can use auth() to verify OAuth access tokens by passing in the acceptsToken parameter. See detailed examples in the guide on verifying OAuth access tokens.