@@ -755,4 +755,129 @@ describe('AuthManager', () => {
755755 expect ( capturedConfig ) . not . toHaveProperty ( 'advanced' ) ;
756756 } ) ;
757757 } ) ;
758+
759+ describe ( 'getPublicConfig' , ( ) => {
760+ it ( 'should return safe public configuration' , ( ) => {
761+ const warnSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
762+ const manager = new AuthManager ( {
763+ secret : 'test-secret-at-least-32-chars-long' ,
764+ baseUrl : 'http://localhost:3000' ,
765+ socialProviders : {
766+ google : {
767+ clientId : 'google-client-id' ,
768+ clientSecret : 'google-client-secret' ,
769+ enabled : true ,
770+ } ,
771+ github : {
772+ clientId : 'github-client-id' ,
773+ clientSecret : 'github-client-secret' ,
774+ } ,
775+ } ,
776+ emailAndPassword : {
777+ enabled : true ,
778+ disableSignUp : false ,
779+ requireEmailVerification : true ,
780+ } ,
781+ plugins : {
782+ twoFactor : true ,
783+ organization : true ,
784+ } ,
785+ } ) ;
786+ warnSpy . mockRestore ( ) ;
787+
788+ const config = manager . getPublicConfig ( ) ;
789+
790+ // Should include social providers without secrets
791+ expect ( config . socialProviders ) . toHaveLength ( 2 ) ;
792+ expect ( config . socialProviders [ 0 ] ) . toEqual ( {
793+ id : 'google' ,
794+ name : 'Google' ,
795+ enabled : true ,
796+ } ) ;
797+ expect ( config . socialProviders [ 1 ] ) . toEqual ( {
798+ id : 'github' ,
799+ name : 'GitHub' ,
800+ enabled : true ,
801+ } ) ;
802+
803+ // Should NOT include sensitive data
804+ expect ( config ) . not . toHaveProperty ( 'secret' ) ;
805+ expect ( config . socialProviders [ 0 ] ) . not . toHaveProperty ( 'clientSecret' ) ;
806+ expect ( config . socialProviders [ 0 ] ) . not . toHaveProperty ( 'clientId' ) ;
807+
808+ // Should include email/password config
809+ expect ( config . emailPassword ) . toEqual ( {
810+ enabled : true ,
811+ disableSignUp : false ,
812+ requireEmailVerification : true ,
813+ } ) ;
814+
815+ // Should include features
816+ expect ( config . features ) . toEqual ( {
817+ twoFactor : true ,
818+ passkeys : false ,
819+ magicLink : false ,
820+ organization : true ,
821+ } ) ;
822+ } ) ;
823+
824+ it ( 'should filter out disabled providers' , ( ) => {
825+ const warnSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
826+ const manager = new AuthManager ( {
827+ secret : 'test-secret-at-least-32-chars-long' ,
828+ socialProviders : {
829+ google : {
830+ clientId : 'google-client-id' ,
831+ clientSecret : 'google-client-secret' ,
832+ enabled : true ,
833+ } ,
834+ github : {
835+ clientId : 'github-client-id' ,
836+ clientSecret : 'github-client-secret' ,
837+ enabled : false ,
838+ } ,
839+ } ,
840+ } ) ;
841+ warnSpy . mockRestore ( ) ;
842+
843+ const config = manager . getPublicConfig ( ) ;
844+
845+ expect ( config . socialProviders ) . toHaveLength ( 1 ) ;
846+ expect ( config . socialProviders [ 0 ] . id ) . toBe ( 'google' ) ;
847+ } ) ;
848+
849+ it ( 'should default email/password to enabled' , ( ) => {
850+ const warnSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
851+ const manager = new AuthManager ( {
852+ secret : 'test-secret-at-least-32-chars-long' ,
853+ } ) ;
854+ warnSpy . mockRestore ( ) ;
855+
856+ const config = manager . getPublicConfig ( ) ;
857+
858+ expect ( config . emailPassword . enabled ) . toBe ( true ) ;
859+ } ) ;
860+
861+ it ( 'should handle unknown provider names' , ( ) => {
862+ const warnSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
863+ const manager = new AuthManager ( {
864+ secret : 'test-secret-at-least-32-chars-long' ,
865+ socialProviders : {
866+ customProvider : {
867+ clientId : 'custom-client-id' ,
868+ clientSecret : 'custom-client-secret' ,
869+ } ,
870+ } ,
871+ } ) ;
872+ warnSpy . mockRestore ( ) ;
873+
874+ const config = manager . getPublicConfig ( ) ;
875+
876+ expect ( config . socialProviders [ 0 ] ) . toEqual ( {
877+ id : 'customProvider' ,
878+ name : 'CustomProvider' ,
879+ enabled : true ,
880+ } ) ;
881+ } ) ;
882+ } ) ;
758883} ) ;
0 commit comments