Example

Here is a full example of how you can use the UAE pass:

import { PassportStrategy } from '@nestjs/passport';
import {
  AuthenticationResult,
  Strategy,
  UAEPassOptions,
} from '@tradinos/cms-backend-passport-uae-pass';

export class UAEPassStrategy extends PassportStrategy(Strategy, 'uae_pass') {
  constructor() {
    const options: UAEPassOptions = {
      tokenURL: 'https://stg-id.uaepass.ae/idshub/token',
      authorizationURL: 'https://id.uaepass.ae/idshub/authorize',
      clientID: 'sandbox_stage',
      clientSecret: 'sandbox_stage',
      callbackURL: 'https://tradinos-cms-back-dev.com/auth/uaepass',
      userProfileURL: 'https://id.uaepass.ae/idshub/userinfo',
    };
    super(options);
  }

  override validate(payload: AuthenticationResult) {
    return payload.profile;
  }
}

override validate(payload: AuthenticationResult)

This method is automatically called by Passport after UAE PASS authentication is successful. It receives the authentication result, which includes tokens and user data.

return payload.profile;

Here, we're returning just the profile field from the result. This object contains the verified user info from UAE PASS (name, Emirates ID, email, phone, etc.). This returned object becomes the authenticated user (req.user) in your app.

In your controller:

Now you should have everything done✅

Last updated