how to check for backface in fragment shader

I try to implement two side lighting by first check if the face is back facing.

checking the dot product between view vector (0,0,-1) and normal vector (in viewspace)

vec3 viewVector = vec3(0,0,-1)-vec3(0,0,0);
float dotProd = dot(viewVector,normal);

vec4 finalColor;
if(dotProd < 0){
	finalColor = diffuseTerm + specularTerm;	
	finalColor = diffuseTerm + specularTerm;

which is correct for most part, except for flat surface that perpendicular to z-axis will keep changing side when turn the camera.

Can someone help me on this ?

Thank in advance

You could just use gl_FrontFacing. That will tell you if the fragment is from a front or back facing triangle.

Thank , It work like a charm.