Skip to content

Commit c22a189

Browse files
authored
Merge pull request #168 from Flagsmith/chores/ignore_undefined_traits
Ignore undefined traits when identifying / calling setTrait(s) or identify
2 parents 225effe + 7501338 commit c22a189

56 files changed

Lines changed: 20 additions & 4357 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/nextjs-middleware/pages/_app.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import '../styles/globals.css'
21
import type { AppProps } from 'next/app'
32

43
function MyApp({ Component, pageProps }: AppProps) {

examples/nextjs-middleware/pages/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { NextPage } from 'next'
22
import Head from 'next/head'
3-
import {ChangeEventHandler, FormEventHandler, useCallback, useState} from "react";
3+
import React, {ChangeEventHandler, FormEventHandler, useCallback, useState} from "react";
44
import nookies from 'nookies'
5+
import Link from 'next/link';
56
const Home: NextPage = () => {
67
const [user, setUser] = useState<string>(nookies.get().user ||"test1")
78
// console.log(nookies.get().user)
@@ -27,7 +28,11 @@ const Home: NextPage = () => {
2728
This project uses the multivariate feature flag as shown in our <a href={"https://flagsmith-realtime-example.vercel.app/"}>realtime multivariate example</a> to give a user a colour based on a abn percentage split.
2829
</p>
2930
<p>
30-
Based on the colour feature flag, the Next.js middleware will redirect he user to a url with that colour as a get parameter
31+
Based on the colour feature flag, the Next.js middleware will redirect he user to a url with that colour as a get parameter.
32+
Once a user is selected and you press login, they will be cookied and you will be redirected to /login.
33+
</p>
34+
<p>
35+
Visiting <Link href={"/login"}>/login</Link> will identify the user in middleware.ts and redirect the user to a page based on their feature flag evaluations.
3136
</p>
3237
<form onSubmit={submit} className="row">
3338
<div className="col-md-4">

flagsmith-core.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,13 @@ const Flagsmith = class {
213213
traits: Object.keys(this.withTraits).map((k)=>({
214214
"trait_key":k,
215215
"trait_value": this.withTraits![k]
216-
}))
216+
})).filter((v)=>{
217+
if (typeof v.trait_value === 'undefined') {
218+
this.log("Warning - attempted to set an undefined trait value for key", v.trait_key)
219+
return false
220+
}
221+
return true
222+
})
217223
})):
218224
this.getJSON(api + 'identities/?identifier=' + encodeURIComponent(identity)),
219225
])

lib/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.js
2+
*.ts
3+
*.tsx

lib/flagsmith-es/README.md

Lines changed: 0 additions & 30 deletions
This file was deleted.

lib/flagsmith-es/index.d.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

lib/flagsmith-es/index.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

lib/flagsmith-es/isomorphic.d.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

lib/flagsmith-es/isomorphic.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

lib/flagsmith-es/next-middleware.d.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)