Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add custom logo property on thirdparty custom providers #741

Merged
merged 6 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/build/recipe/thirdparty/providers/custom.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions lib/build/recipe/thirdparty/providers/types.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/build/thirdparty-shared.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/version.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions lib/ts/recipe/thirdparty/providers/custom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ import Provider from ".";
* Class.
*/
export default class Custom extends Provider {
private logo: JSX.Element | undefined;
/*
* Constructor.
*/
constructor(config: CustomProviderConfig) {
super(config);
this.logo = config.logo;
}

getLogo = (): undefined => {
return undefined;
getLogo = (): JSX.Element | undefined => {
return this.logo;
};

/*
Expand Down
5 changes: 5 additions & 0 deletions lib/ts/recipe/thirdparty/providers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ export type CustomProviderConfig = {
*/
name: string;

/**
* Provider Logo.
*/
logo?: JSX.Element;

/*
* Button Component
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/ts/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
export const package_version = "0.35.0";
export const package_version = "0.35.1";
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "supertokens-auth-react",
"version": "0.35.0",
"version": "0.35.1",
"description": "ReactJS SDK that provides login functionality with SuperTokens.",
"main": "./index.js",
"engines": {
Expand Down
14 changes: 13 additions & 1 deletion test/unit/recipe/thirdparty/signInUp.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ describe("ThirdParty.SignInAndUp", () => {
recipeList: [
Recipe.init({
signInAndUpFeature: {
providers: [Github.init()],
providers: [
Github.init(),
{
id: "custom",
name: "Custom",
logo: "LOGO" as any,
},
],
},
useShadowDom: false,
}),
Expand Down Expand Up @@ -86,6 +93,11 @@ describe("ThirdParty.SignInAndUp", () => {
});
});

test("check if the logo is rendered, when a logo is provided for custom providers", async () => {
const result = render(<SignInAndUp />);
expect(await result.findByText("LOGO")).toBeInTheDocument();
});

test("not redirect if session exists but redirectOnSessionExists=false", async () => {
// when
const result = render(<SignInAndUp redirectOnSessionExists={false}> mockRenderedText </SignInAndUp>);
Expand Down
25 changes: 25 additions & 0 deletions test/unit/recipe/thirdparty/thirdParty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,31 @@ describe("ThirdParty", function () {
);
});

it("Initializing ThirdParty with custom provider and custom logo if provided", async function () {
ThirdParty.init({
signInAndUpFeature: {
providers: [
{
id: "slack",
name: "Slack",
logo: "LOGO" as any,
},
],
},
}).authReact(SuperTokens.getInstanceOrThrow().appInfo, false);
assert.notDeepStrictEqual(ThirdParty.getInstanceOrThrow(), undefined);
assert.deepStrictEqual(ThirdParty.getInstanceOrThrow().config.recipeId, "thirdparty");
assert.deepStrictEqual(
ThirdParty.getInstanceOrThrow().config.appInfo,
SuperTokens.getInstanceOrThrow().appInfo
);
assert.deepStrictEqual(ThirdParty.getInstanceOrThrow().config.signInAndUpFeature.providers.length, 1);
assert.deepStrictEqual(
ThirdParty.getInstanceOrThrow().config.signInAndUpFeature.providers[0].getLogo(),
"LOGO"
);
});

it("Initializing ThirdParty with Google twice only shows a warning and filters duplicate", async function () {
ThirdParty.init({
signInAndUpFeature: {
Expand Down
11 changes: 11 additions & 0 deletions test/with-typescript/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@ function getThirdPartyConfigs() {
name: "Custom",
buttonComponent: <span>ASDF Custom</span>,
},
{
id: "custom-2",
name: "Custom-2",
logo: <svg></svg>,
buttonComponent: <span>ASDF Custom</span>,
},
],
},
oAuthCallbackScreen: {
Expand Down Expand Up @@ -493,6 +499,11 @@ function getThirdPartyEmailPasswordConfigs() {
{
id: "custom",
name: "Custom",
logo: <svg></svg>,
},
{
id: "custom-2",
name: "Custom-2",
},
],
},
Expand Down
Loading