Social Login
Social login allows users to authenticate using their existing social media accounts such as Google or Facebook.
ZeroDev supports social logins natively, but you can also use ZeroDev with third-party auth providers such as Dynamic, Privy, and Magic if you prefer their UI.
Setup
ZeroDev offers two modes for setting up social login: Development and Production. Follow the steps below to configure your social login in our dashboard.
-
Development Mode:
- Available to all users by default.
- Functions only when your application is running locally on the
localhost
URI. - Ideal for testing social sign-in features during development.
-
Production Mode:
- Available to users on the "Growth" plan or higher.
- To activate, complete the form in the Social Auth section of the ZeroDev dashboard.
- Submit the form for review; reviews are typically completed within 24 hours.
- Ensure all sections of the form are completed accurately to facilitate a successful review.
- ZeroDev uses Magic for its social integration. Links to Magic's documentation are provided in the form to assist with setup (e.g., Google Developer Console).
Production Mode Configuration Steps:
- Enter the client ID and client secret from your social provider into the designated fields in the ZeroDev dashboard.
- Copy the redirect URI provided by ZeroDev into your social provider’s dashboard.
- Ensure that the redirect URI and whitelist URI for your application are input correctly in the form.
- Submit the form for review.
For detailed information on how Magic handles the creation of public/private key pairs, integral to the security of the social login process, please refer to Magic's product security documentation.
Installation
npm i @zerodev/social-validator
API
isAuthorized
Checks if the user is authorized. In a web app, this is typically called on page load to check if the user is logged in.
isAuthorized({ projectId: string }): Promise<boolean>
Parameters
- projectId (string): Your ZeroDev project ID.
Returns
Promise<boolean>
: Resolves to true if the user is logged in, otherwise false.
Example
import { isAuthorized } from "@zerodev/social-validator"
const authorized = await isAuthorized({ projectId: 'your_project_id' });
console.log(authorized); // true or false
initiateLogin
Initiates a social login process by redirecting the user to the specified OAuth provider.
After a successful login, the user will be redirected back to your app. You may then call the getSocialValidator
function to create a Kernel account using the social validator as the sudo validator.
initiateLogin({
socialProvider: "google" | "facebook",
oauthCallbackUrl?: string,
projectId: string
})
Parameters
- socialProvider ("google" | "facebook"): The social provider to use for login.
- oauthCallbackUrl (string, optional): The URL to redirect to after login. Defaults to the current window location if not provided.
- projectId (string): Your ZeroDev project ID.
Example
import { initiateLogin } from "@zerodev/social-validator"
initiateLogin({
socialProvider: "google",
projectId: "your_project_id"
});
getSocialValidator
Gets a social validator for the specified entry point. Use this function after a successful login to create a Kernel account using the social validator as the sudo validator.
export async function getSocialValidator<
entryPointVersion extends EntryPointVersion
>(
client: Client,
{
entryPoint,
kernelVersion,
projectId
}: {
entryPoint: EntryPointType<entryPointVersion>
kernelVersion: GetKernelVersion<entryPointVersion>
projectId: string
}
): Promise<KernelValidator<"SocialValidator">>
Parameters
- client (Client): The client instance.
- entryPoint (entryPoint): The entry point object.
- projectId (string): Your ZeroDev project ID.
Returns
Promise<KernelValidator<"SocialValidator">>
: Resolves to a social validator object.
Example
import { getSocialValidator } from "@zerodev/social-validator"
const socialValidator = await getSocialValidator(
publicClient,
{
entryPoint: getEntryPoint("0.7"),
projectId: "your_project_id"
}
);
logout
Logs out the current user.
logout({ projectId: string })
Parameters
- projectId (string): Your ZeroDev project ID.
Example
import { logout } from "@zerodev/social-validator"
await logout({ projectId: "your_project_id" });