Skip to content

Feature request: Tell onSuccess if the user has signed up or just signed in #372

@mcky

Description

@mcky

Problem:
I'm using the WorkOS events API to sync user profiles, organisations and org memberships to my own database for use in authorization checks and to model relations between entities and users/orgs.

When a user signs up or logs in, the onSuccess callback triggers a check to see if the user exists in our database or not, and creates records for them if not. We have some specific logic that needs to run only on sign-up but before users can access the app (therefor the event syncing background job may not have completed)

Proposed solution(s)

  1. Pass an additional arg to the onSuccess callback
export interface HandleAuthOptions {
    //...rest
    eventType: 'sign-up' | 'sign-in';
}

export const GET = handleAuth({
  async onSuccess({ eventType }) {
    if (eventType === 'sign-up') {
      await additionalOnboardingLogic()
    }
  }
})
  1. Provide different callbacks for sign up and sign in

Alternatives I've considered

  • Passing the state param to getSignUpUrl to differentiate sign-up from sign-in, but a user is able to click log in and then from the hosted AuthKit UI, change the flow to sign-up. This means the state param would then be invalid.
  • Using webhooks instead in the hope they will be delivered in time for our onboarding logic to run, but I'd rather use the events API instead where possible since WorkOS has no capability for simulating webhooks for testing as stripe does
  • Holding the user on a page until the background sync has finished: I'll probably have to do this for now

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions