Server Actions

The Memberstack Nextjs package comes with server side actions that you can use instead of the admin package that use fetch so you can take advantage of the nextjs cache mechanism

You can initialize the Memberstack class singleton with your memberstack api key

import { Memberstack } from '@memberstack/nextjs'

export const memberstack = new Memberstack({
    apiKey: '...'
})

Which then returns an object with the following async functions:

getApp()

API

const app = await getApp()

Arguments

None

Returns

{
      id: string;
      name: string;
      mode: "live" | "sandbox";
      plans: Plan[];
      contentGroups: RestrictedUrlGroup[];
      emailVerificationEnabled: boolean;
      requireEmailVerification: boolean;
      customField: CustomField[];
      branding: Branding;
      authProviders: AuthProvider[];
};

getUser()

API

const user = await getUser()

Arguments

None

Returns

{
  id: string;
  verified: boolean;
  profileImage: string;
  auth: {
    email: string;
    hasPassword: boolean;
    providers: {
      provider: string;
    }[];
  };
  loginRedirect: string;
  stripeCustomerId: string;
  createdAt: string;
  metaData: object;
  customFields: object;
  permissions: string[] | [];
  planConnections: MemberPlanConnection[];
};

getPlans()

API

const plans = await getPlans()

Arguments

None

Returns

{
  id: string;
  name: string;
  description: string;
  status: string;
  redirects: {
    afterLogin: string;
    afterLogout: string;
    afterSignup: string;
  };
  prices?: Transforms["Price"][] | [];
}[]

getPlan({planId})

signupWithPassword({email, password, customFields, metaData, captchaToken, plans})

signupPasswordless({email, customFields, passwordlessToken, metaData, captchaToken, plans})

loginWithPassword({email, password})

loginPasswordless({email, passworldlessToken})

logout()

sendVerificationEmail()

sendResetPasswordEmail({email})

resetPassword({token, newPassword})

createCheckoutUrl({priceId, couponId, cancelUrl, successUrl})

createCustomerPortal({priceIds, configuration, returnUrl})

updateMemberAuth({email, oldPassword, newPassword})

updateMemberCustomField({customFields})

Notes:

The useCookie flag is automatically set to true by default when initializing memberstack in the react and nextjs package. The name for for the cookie is _ms-mid and is passed to each fetch call action.

Last updated